Skip to content
Live tests

Live tests

The offline tests prove that the client builds the requests it means to build. They cannot prove that the SciX / ADS server understands those requests the way the client assumes. The live suite in tests/live/ does that: each test sends a handful of real requests and checks one assumption about the server. Its docstring states the assumption in plain words and names what in the client depends on it, so the list of failures reads as a list of broken assumptions.

Running it

CommandWhat runs
uv run pytestEverything offline. Every live test is skipped, and the run is guarded: any attempt to resolve a host name or connect a network socket fails the test that makes it.
uv run pytest --liveAlso the read-only live tests. Tests that need the API are skipped if no token can be found; the schema-drift test needs no token (it reads GitHub).
uv run pytest --live --live-library IDAlso the tests that read a public library (ID is its id; or set SCIX_LIVE_LIBRARY=ID).
uv run pytest --live --live-writeAlso the tests that create, change and delete libraries. They only touch libraries they create, and delete them all at the end. --live-write without --live is a usage error.

Useful additions:

  • uv run pytest --live tests/live runs only the live tests; add -rs to see why tests were skipped.
  • uv run pytest --live tests/live/test_query_syntax.py -k negation runs part of the suite. Shared results (the pinned records, the probes) are still fetched once, so a subset costs a few requests.
  • -m "live and not live_write" selects by marker. The markers are live (every live test, registered in pyproject.toml) and live_write (registered by tests/conftest.py).

The token

The token is found exactly as the client finds it, by scixplorer._config.config.resolve_tokens(): the environment variable SCIX_API_TOKEN (or ADS_API_TOKEN, ADS_DEV_KEY), else the first line of ~/.scix/token (or ~/.ads/token, ~/.ads/dev_key). Without one, the API tests are skipped with the message “no API token: set SCIX_API_TOKEN …”. The token is never printed: the transport records no request headers, error texts are redacted where the suite builds them, and a report hook replaces the token in every failure text and captured output with [REDACTED].

The request budget

ADS allows about 5000 search requests a day per token, and far fewer for some services. The suite is designed to need fewer than 130 requests in the worst case and about 60 to 100 in a normal run:

PartWorst caseWhen everything passes
Shared fixtures: pinned records (1), default fields (1), sample (1), probes (at most 10)134
test_records.py (deferred fields, at most 4)41
test_fields.py (fields missing from the schema, at most 3)31
test_exactness.py (=field table at most 7, author counts 2, =bibcode 2)116
test_query_syntax.py2726
test_operators.py99
test_paging.py88
test_services.py (one request per service)66
test_libraries.py22
test_authors.py (per-author arrays and pos(): all checks in one request, then one per check, at most 9)101
--live9364
test_libraries.py with --live-library (paging at most 4)+10+9
test_libraries_write.py with --live-write (16 changes, 6 deletions)+22+22
With both flags12595

Retries are extra: the live client retries a 502/503/504 once, and the retry counts. The schema-drift test makes one request to GitHub, which is not counted.

How the budget is kept, all in tests/live/support.py (LiveTransport):

  • One session-scoped client sends every request through a counting transport, and is made the default client, so a lazy load or a library method cannot bypass it.
  • Identical search requests (/search/query, /search/bigquery; same parameters, body and token) are answered from a session cache and not counted. Tests that need the same count share it.
  • Hard limit. The transport refuses request 151: the test making it fails with BudgetExhausted (a BaseException, so no except Exception can swallow it), and the session stops after that test, running every teardown.
  • HTTP 429. After a 429 from any service, that test and every later live test is skipped with “ADS answered HTTP 429 (rate limit exceeded) for SERVICE (it resets at …)”. Nothing more is sent.
  • Library cleanup bypasses both the limit and the 429 stop.
  • Where many fields or probes are checked, one request checks them all together and failing groups are split to find the culprits (“group testing”, support.isolate and support.peel), under a fixed cap of requests. Anything not settled within the cap is reported as undetermined (a skip, or a row of a table). The per-author checks (test_authors.py) instead send everything together and, only if that fails, each check alone: their failures tend to come several at a time (a whole class of fields ignoring positions), where that needs fewer requests and settles every check.

At the end of a --live run two sections are printed: live API requests (requests per service, cache hits, and the rate limits the server last reported) and live API findings (observations that are recorded rather than asserted: accept/reject tables, measured limits, values the client coerces, schema drift).

Reading a failure

A failure message starts with the assumption, then shows the request and the answer. For example:

AssertionError: =title:"<the whole title>" (no synonyms) matches the record with that title.
  probe:    record 1998AJ....116.1009R must match =title:"..."
  q:        bibcode:"1998AJ....116.1009R" AND =title:"..."
  request:  GET /search/query {'fl': 'bibcode', 'sort': 'score desc,id asc', 'start': 0, 'rows': 0}
  error:    400 GET /search/query: <the server's error text>
  • q is exactly the Solr query the client sent, request the other parameters, and error the server’s own message (or numFound if it answered).
  • A probe checks that one pinned record matches (or does not match) one clause, as bibcode:"R" AND clause. “Found failing by elimination” means the evidence is the request of the group that held the probe.
  • “the compiler no longer emits the form this live test checks” means solr.py changed: the test would now check something else, so update the expected form in the test.
  • An error in a fixture (pinned, sample, full_records) fails every test that uses it with the same message. A pinned bibcode that no longer exists is replaced in tests/live/harness.py:PINNED.
  • A skip saying “not isolated” means a group holding that check failed and the request cap was reached; the checks that were isolated report their own failures. Fix those and run again.
  • SchemaDriftWarning (and the findings) list schema fields the model does not cover and other differences that are not errors.

What to change when an assumption is broken:

Failing testAssumptionWhat to change in the client
test_records.py::test_bibcode_list_returns_exactly_the_listed_recordsbibcode:("A" OR "B") returns exactly the listed recordssolr._compile_in; config.max_inline_bibcodes
test_records.py::test_default_field_list_is_acceptedOne request with every stored, non-deferred field in fl is acceptedDocument._deferred, or the field that is rejected (stored=False)
test_records.py::test_default_fields_load_without_data_warningsEvery returned value converts to its field’s typeThe class of the field named in the warning (models/document.py)
test_records.py::test_default_fields_have_declared_typesLoaded values are None or the type Document.describe() declaresField.to_python / _to_python of that field class
test_records.py::test_default_fields_are_lists_exactly_when_multivaluedThe JSON is a list exactly when the field is multivaluedmultivalued= of the named field
test_records.py::test_score_is_returned_by_search_queryscore is returned when requestedDocument.score (make it search-only if never returned)
test_records.py::test_deferred_fields_can_be_selectedSelecting ack, body, caption, citation, credit, mention, reference is acceptedMake the rejected field search-only (stored=False), so that it is never put in fl
test_records.py::test_deferred_fields_have_declared_typesDeferred fields have their declared typesThe class or multivalued= of the named field
test_fields.py::test_search_alias[...]arxiv:, collection:, affil:, inst:, orcid:, full:, abs: are accepted and matchThe VirtualField of that name; schema_report.QUERY_PARSER
test_fields.py::test_field_missing_from_schema_is_searchable[...]grant_agencies: and grant_id: are accepted although schema.xml lacks themRemove Document.grant_agencies / grant_id
test_fields.py::test_not_indexed_fields_are_returnedlinks_data and page_range are returnedTheir definitions in models/document.py
test_query_syntax.py::test_fielded_phrasetitle:"w1 w2" is a phrase matchsolr.QUOTED_FIELD_TYPES
test_query_syntax.py::test_integer_equalityyear:1998 matches although Solr keeps year as a stringsolr.QUOTED_FIELD_TYPES; Document.year (IntegerField)
test_query_syntax.py::test_integer_range_partition_on_year[a TO b] is inclusive, * is open, year > x is [x+1 TO *]IntegerField.step; solr._compile_range
test_query_syntax.py::test_integer_range_partition_on_citation_countThe same on citation_countIntegerField.step; solr._compile_range
test_query_syntax.py::test_open_ended_range_on_author_countauthor_count:[101 TO *] returns only records with more than 100 authorsDocument.author_count
test_query_syntax.py::test_float_exclusive_boundx > v as (x:[v TO *] AND -x:v) excludes exactly vsolr._compile_range (fields without Field.step)
test_query_syntax.py::test_datetime_range_with_quoted_timestampsentry_date:["2016-01-01T00:00:00Z" TO *] is accepted and exactsolr.QUOTED_FIELD_TYPES (DateTimeField); solr._compile_range
test_query_syntax.py::test_relative_datetime_literalentry_date:[NOW-7DAYS TO *] finds last week’s recordsexpr.days_ago; solr.format_value (SolrLiteral)
test_query_syntax.py::test_month_precision_date_rangepubdate:[2020-01 TO 2020-06] includes all of JuneDateField.to_solr; DateField.step
test_query_syntax.py::test_negation_alone*:* AND -clause returns records not matching the clausesolr._compile_and
test_query_syntax.py::test_and_nota AND -b excludes bsolr._compile_and
test_query_syntax.py::test_or_nota OR (*:* AND -b) is a valid nested negationsolr._compile_and; solr._operand
test_query_syntax.py::test_not_of_group*:* AND -(a AND b) negates the whole groupsolr._operand
test_query_syntax.py::test_nothing_matches_nothing*:* AND -*:* finds nothingsolr._NOTHING
test_query_syntax.py::test_integer_value_listyear:(2014 OR 2015) matches either yearsolr._compile_in
test_query_syntax.py::test_inline_bibcode_list_at_the_limit50 bibcodes fit inline in one GETconfig.max_inline_bibcodes
test_query_syntax.py::test_long_affiliation_id_list1000 aff_id values fit in one GET (the findings give the query length)search.MAX_RELATED_VALUES
test_query_syntax.py::test_single_token_wildcardtitle:exoplan* is a prefix matchsolr._compile_pattern
test_query_syntax.py::test_escaped_specials_in_wildcardtitle:star\-form* is acceptedsolr._LUCENE_SPECIALS
test_query_syntax.py::test_wildcard_inside_phraseauthor:"Last, I*" matches that authorsolr._compile_pattern (quoted form)
test_query_syntax.py::test_leading_wildcardtitle:*astro* is answered, not rejectedTextExpr.contains (forbid it on Document if rejected)
test_exactness.py::test_exact_prefix_on_every_text_and_name_field=field:"a" is accepted on every text and name field (table in the message)Field.match_kind of each rejected field; solr.EXPANDED_MATCH_KINDS
test_exactness.py::test_exact_author_matches_its_record=author:"Last, First M." matches that exact nameNameField.match_kind
test_exactness.py::test_exact_author_is_no_broader=author: never finds more than author:NameField documentation (SPEC section 5)
test_exactness.py::test_exact_author_with_full_first_name_is_narrower=author:"Last, First" finds strictly fewer records than author:"Last, First"NameField documentation (SPEC section 5)
test_exactness.py::test_exact_title_matches_its_record=title:"<whole title>" matchesTextField.match_kind
test_exactness.py::test_exact_prefix_on_bibcode_matches_nothing=bibcode:"X" does not match X; bibcode:"X" doesOnly SPEC section 5 and the StringField docstring (the client never sends = on keywords)
test_exactness.py::test_exact_inside_positionpos(=author:"…", 2) is accepted and matchessolr._compile_func
test_exactness.py::test_position_one_is_the_first_authorpos(author:"…", 1) is the first authorTextExpr.__getitem__
test_exactness.py::test_position_tests_the_positionpos(author:"<second>", 1) does not matchTextExpr.__getitem__
test_exactness.py::test_position_two_argument_formpos(author:"…", 2) is the second authorsolr._compile_func
test_exactness.py::test_position_three_argument_formpos(author:"…", 1, 3) covers positions 1 to 3TextExpr.__getitem__ (slices)
test_exactness.py::test_first_author_fieldfirst_author:"…" matches the first authorDocument.first_author
test_operators.py::test_citations_of_a_recordcitations(bibcode:"X") returns records citing XDocument.citations
test_operators.py::test_references_of_a_recordreferences(bibcode:"X") returns X’s referencesDocument.references
test_operators.py::test_operator_accepts_fielded_query[...]trending, useful, reviews, similar accept a fielded sub-queryThat operator in models/document.py
test_operators.py::test_operator_accepts_raw_stringtrending(exoplanets) is accepteddocument._operand (str arguments)
test_operators.py::test_topn_takes_the_top_of_a_sorted_querytopn(5, a AND b, citation_count desc) is the top fiveDocument.top_n; solr._func_arg (parenthesise the sub-query if this fails)
test_paging.py::test_default_sort_is_acceptedsort=score desc,id asc is acceptedsearch._sort (the id tiebreaker)
test_paging.py::test_sort_by_citation_countcitation_count desc,id asc sortssolr.compile_order; search._sort
test_paging.py::test_consecutive_pages_do_not_overlapstart/rows pages do not overlapSearchBackend.run
test_paging.py::test_rows_zero_returns_the_countrows=0 returns numFound onlySearchBackend.count
test_paging.py::test_largest_page_is_returned_in_fullrows=2000 returns 2000 documentssearch.MAX_PAGE_SIZE
test_paging.py::test_rows_above_the_largest_pagerows=2001 is capped or rejectedsearch.MAX_PAGE_SIZE (could be raised)
test_paging.py::test_deep_startstart=1000000 worksSearchBackend.run
test_paging.py::test_bigquery_upload_with_bitset_filterA bigquery POST (fq={!bitset}, big-query/csv) returns only uploaded recordsSearchPlan.request
test_paging.py::test_bigquery_returns_scoreBigquery returns scoreDocument.score
test_paging.py::test_bigquery_count_is_the_upload_sizeBigquery with rows=0 counts the uploadSearchBackend.count
test_paging.py::test_bigquery_query_filters_the_uploadA bigquery q filters the uploadsearch._finish (what stays in q)
test_paging.py::test_bigquery_sort_start_and_rowsBigquery honours sort, start, rowsSearchPlan.request; SearchBackend.run
test_libraries.py::test_library_listingGET /biblib/libraries lists libraries with ids, with the declared typesLibraryBackend; the Library field classes
test_libraries.py::test_unknown_library_id_yields_no_rowAn unknown library id is answered 404LibraryBackend._fetch (the 404 check)
test_libraries.py::test_get_public_library_by_idA public library’s metadata can be fetched by idfetch_library
test_libraries.py::test_fetch_bibcodes_paging_is_consistentstart/rows paging of a library’s bibcodes is consistentmodels.library.fetch_bibcodes; DEFAULT_PAGE_SIZE
test_libraries.py::test_docs_library_counts_its_documentsdocs(library/<id>) finds 1 to num_documents documentsconfig.library_membership (switch the default to "bibcodes" if this fails)
test_libraries.py::test_docs_library_matches_its_membersmembers AND docs(library/<id>) finds every memberas above
test_libraries.py::test_not_docs_library_excludes_its_membersmembers AND -docs(library/<id>) finds noneas above
test_libraries_write.py::test_create_without_documentsCreating with no bibcodes gives an empty libraryLibrary.create; Library._created
test_libraries_write.py::test_create_with_documentsCreating with bibcodes stores themmodels.library._create_request
test_libraries_write.py::test_add_reports_number_addedAdding answers number_addedLibrary.add
test_libraries_write.py::test_remove_reports_number_removedRemoving answers number_removedLibrary.remove
test_libraries_write.py::test_add_and_remove_change_num_documentsnum_documents follows adds and removesLibrary._change
test_libraries_write.py::test_update_changes_name_and_descriptionPUT /biblib/documents/<id> updates metadatamodels.library._update_request
test_libraries_write.py::test_empty_removes_every_documentThe empty operation emptiesLibrary.empty
test_libraries_write.py::test_set_operation_creates_a_library[...]union, intersection, difference create the combined libraryLibrary._combine; _operation_request
test_libraries_write.py::test_docs_of_a_new_private_librarydocs(library/<id>) works for a private libraryconfig.library_membership
test_services.py::test_rate_limit_headers_are_parsedX-RateLimit-* headers are present and parsedClient._observe; client._parse_timestamp
test_services.py::test_invalid_token_raises_authentication_errorA bad token is answered 401/403client._error_for
test_services.py::test_export_bibtex/export/bibtex answers {"export": text}services.export._export
test_services.py::test_resolver_lists_external_resources/resolver/<bibcode> answers links.recordsservices.resolver.external_resources
test_services.py::test_resolver_answers_one_link_type_with_json/resolver/<bibcode>/esource answers 200 JSON, not a redirectservices.resolver.external_resource (follow redirects, or return the Location)
test_services.py::test_vis_author_network/vis/author-network takes bibcodes and answers dataservices.vis._request; _network
test_services.py::test_citation_helper/citation_helper answers the documented list of dictsservices.citation_helper (its docstring)
test_authors.py::test_per_author_arrays_have_one_entry_per_authoraff, aff_id, email and the three ORCID arrays have one entry per author (the findings show the counts per record)scixplorer.model.Collection.records (Document.authors); Document.affiliation
test_authors.py::test_missing_per_author_values_are_a_dashAn author without a value has "-" in those arrays, never null or "" (the findings also show how several affiliations are written in aff and aff_id)placeholder= in scixplorer.models.author.document_authors
test_authors.py::test_position_on_per_author_field[...]pos(field:"v", n) is accepted, matches author n’s value and not another author’s, on aff_id, aff, email, orcid and each ORCID array. A field in search.POSITIONAL_FIELDS must pass; for one that is not, a pass means it could be added and an xfail is what the client already assumes. The findings table lists every fieldsearch.POSITIONAL_FIELDS
test_authors.py::test_set_inside_positionpos(aff_id:("a" OR "b"), n) matches when one of the ids is author n’ssearch._position (send one pos() per id instead)
test_authors.py::test_aff_id_matches_each_id_of_an_entry_with_severalaff_id:"<id>" matches a record whose entry for an author is "<id>; <other>", for either id (skipped if no pinned author has several)Document.affiliation / Author.affiliation (which send single ids); separator= in document_authors
test_schema.py::test_document_matches_the_published_schemaEvery modelled field is in schema.xml with the same class, multivaluedness and storageThe named field in models/document.py; KNOWN_UNSCHEMED in tests/live/test_schema.py; schema_report.DELIBERATE

How the tests stay robust as the index changes

  • Nothing is assumed about the five pinned records (harness.PINNED) except that their bibcodes exist. The first request fetches them, and every expectation (names, title words, year, references, aliases’ values) is derived from that answer.
  • Counts are compared as identities within a fixed closed set S, bibstem:"AJ" AND year:[2014 TO 2017]: for example numFound(S AND year <= 2015) + numFound(S AND year > 2015) == numFound(S). Citation counts change daily, but not between requests seconds apart.
  • Otherwise a test returns a few rows and checks each one client-side (every returned title contains “astro”), or checks one record (bibcode:"R" AND clause).

Not covered

  • Library permissions (get_permissions, set_permissions) and transfer: they need a second ADS account.
  • The lower bound of a month-precision range: test_month_precision_date_range checks that the upper month is included in full and that nothing outside the range is returned, but not that all of the first month is included (that would need another request).
  • =author narrowing is checked on one prolific author; a name with no initial-only variants would make the strict test fail without any client bug.
  • vis.paper_network, the other export formats and the async client paths make the same kind of requests as the ones tested and are not sent, to save requests.