vomebook commited on
Commit ·
fa4486f
1
Parent(s): 29078f2
Upgrade Space runtime and reader dependencies
Browse filesFiles changed (5)
1233456789101011121312 unmodified lines262728292930313220 unmodified lines5354555656575859605961626364656263666768666970717245 unmodified lines11811912011812112212312431 unmodified lines15615715815615916016116213 unmodified lines176177178176179180181182# Pin the published generation for reproducible builds without build arguments.# An explicit SEARCH_DATA_GENERATION selects another immutable bucket generation.FROM node:26.11.1-bookworm-slim AS search-generationFROM node:26.13.1-bookworm-slim AS search-generationARG SEARCH_DATA_GENERATION=5c80388b465f35f74711c17aef9e31f8bb1c04fc0553e9820ac271658d740639WORKDIR /buildCOPY scripts/data/fetch_search_generation.mjs /build/fetch_search_generation.mjsRUN node /build/fetch_search_generation.mjs "$SEARCH_DATA_GENERATION" space /selected \ && printf '%s\n' "$SEARCH_DATA_GENERATION" > /requested-generation
FROM node:26.11.1-bookworm-slim AS source-check-nodeFROM node:26.13.1-bookworm-slim AS source-check-node
WORKDIR /checkCOPY package.json package-lock.json eslint.config.mjs jsconfig.json pyrightconfig.json pyrightconfig.strict.json ./12 unmodified linesRUN npm run check:static \ && node --test tests/data/test_search_generation_fetch.mjs
FROM python:3.11.17-slim AS source-check-pythonFROM python:3.15.2-slim-trixie AS source-check-python
WORKDIR /checkCOPY requirements.txt ruff.toml ./20 unmodified lines tests.search.backend.test_search_runtime_entry \ tests.search.backend.test_search_start_script
FROM node:26.11.1-bookworm-slim AS static-gate-testFROM node:26.13.1-trixie-slim AS static-gate-test
WORKDIR /check# Use the source-checked Python and matching Debian runtime libraries, not# extension modules built for a different interpreter or distribution.RUN apt-get update && apt-get install -y --no-install-recommends python3 \RUN apt-get update && apt-get install -y --no-install-recommends \ libbz2-1.0 libcrypt1 libexpat1 libffi8 libgdbm-compat4t64 libgdbm6t64 \ liblzma5 libncursesw6 libreadline8t64 libsqlite3-0 libssl3t64 libuuid1 zlib1g \ && rm -rf /var/lib/apt/lists/*COPY --from=source-check-node /check/ /check/COPY --from=source-check-python /usr/local/lib/python3.11/site-packages/ /tmp/python-static-tools/COPY --from=source-check-python /usr/local/bin/ruff /tmp/python-static-tools/bin/ruffCOPY --from=source-check-python /usr/local/ /usr/local/COPY ruff.toml ./COPY config/dependencies/static-check.txt config/dependencies/static-check.txtENV PYTHONPATH=/tmp/python-static-toolsRUN python3 -B -c 'import sys, bz2, ctypes, lzma, sqlite3, ssl, coverage; assert sys.version_info[:3] == (3, 15, 2)'RUN npx --no-install pyright --project pyrightconfig.json \ && npx --no-install pyright --project pyrightconfig.strict.json \ && python3 -B -m unittest -v tests.gates.test_static_shards_runner tests.gates.test_package_resolution \45 unmodified lines && node scripts/search/check_download_controller_coverage.mjs \ && printf 'static gate tests passed\n' >/check/static-gate-test-ok
FROM node:26.11.1-bookworm-slim AS static-assetsFROM node:26.13.1-bookworm-slim AS static-assets
ARG ESBUILD_VERSION=0.28.2ARG READER_BUILD_REV=20261009-reader-proxy-cleanup31 unmodified lines && mv /out/sw.min.js /out/sw.jsRUN node /build/check_reader_release.mjs --project hf --root /build --artifact-root /out
FROM python:3.11.17-slim AS search-index-buildFROM python:3.15.2-slim-trixie AS search-index-build
WORKDIR /buildRUN apt-get update && apt-get install -y --no-install-recommends gcc libc6-dev \13 unmodified lines tests.search.backend.test_wildcard_index_oracle.WildcardIndexOracleTests.test_unicode_engine_has_no_equivalents_for_accelerated_ranges \ tests.data.test_generated_data_oracle
FROM python:3.11.17-slimFROM python:3.15.2-slim-trixie
WORKDIR /app
12123ruff==0.17.3coverage==7.17.0ruff==0.17.5coverage==7.17.3mutmut==3.8.111233456fastapi==0.162.0fastapi==0.163.1starlette==1.10.0pydantic==2.14.2pydantic==2.14.3uvicorn==0.54.0uvloop==0.23.0httptools==0.9.078 unmodified lines79808182828384853 unmodified lines899091929293949495969778 unmodified lines sha256: "0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551" }, zipLicense: { url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.24.0/LICENSE", url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.25.0/LICENSE", file: "LICENSE_zipjs", sha256: "1b7ebc8d7889ed25491484ab2b102370742ca6c0b26650a0c62cc2269b579b84" },3 unmodified lines sha256: "b7ca4450b19559a1d50eb381adcee94b82449674be4cd17789d9beba7e6122a1" }, zip: { url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.24.0/index.min.js", url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.25.0/index.min.js", file: "zip.js", sha256: "6c13caf4b90e08323f404f596c51549cdc6b01010bd43935a0bdc6a25bd61021" sha256: "715a4067bb71d750d4af8e60390e48894072f65501e0442e53f252cbfc45cfbc" }, textLayer: { url: "https://cdn.jsdelivr.net/gh/mozilla/pdf.js@v6.5.438/web/text_layer_builder.css",80 unmodified lines818283848485868687888936 unmodified lines126127128129129130131132532 unmodified lines665666667668669668669670671672673674101 unmodified lines7767777787777797807817827 unmodified lines7907917927917937947957965 unmodified lines8028038048038048058068078088094 unmodified lines8148158168158168178188198188208218228231 unmodified line82582682782682882983083124 unmodified lines85685785885785885986086186286312 unmodified lines87687787887787887988088188288388488588488688788888918 unmodified lines908909910909910911912913914915916917918919912920921922923924925926919927928929930287 unmodified lines121812191220121312211222122312241225121812261227122812291230123112241232123312341235123612371230123812391240124112421235124312441245124646 unmodified lines1293129412951288129612971298129922 unmodified lines1322132313241317132513261327132880 unmodified lines source_index, verified_index = source[0], verified[0] test.assertLess(source_index, verified_index) test.assertLess(verified_index, len(stages) - 1, "verified stage must precede the final image") test.assertEqual(stages[source_index][0], ["python:3.11.17-slim", "AS", "source-check-python"]) test.assertEqual(stages[source_index][0], ["python:3.15.2-slim-trixie", "AS", "source-check-python"]) test.assertEqual(stages[verified_index][0], ["source-check-python", "AS", "search-index-verified"]) test.assertEqual(stages[-1][0], ["python:3.11.17-slim"], "unexpected final image") test.assertEqual(stages[-1][0], ["python:3.15.2-slim-trixie"], "unexpected final image")
# Do not allow a preceding ENV, SHELL, RUN, WORKDIR or COPY to replace the # interpreter, tests, or dependencies while leaving a plausible RUN chain.36 unmodified lines generation = [(words, body) for words, body in stages if len(words) == 3 and words[2] == "search-generation"] test.assertEqual(len(generation), 1) test.assertEqual(generation[0][0], ["node:26.11.1-bookworm-slim", "AS", "search-generation"]) test.assertEqual(generation[0][0], ["node:26.13.1-bookworm-slim", "AS", "search-generation"]) pinned = "5c80388b465f35f74711c17aef9e31f8bb1c04fc0553e9820ac271658d740639" test.assertEqual([(op, tuple(value.split())) for op, value in generation[0][1]], [ ("ARG", (f"SEARCH_DATA_GENERATION={pinned}",)),532 unmodified lines self.assertIn('392f4df89533b50f1dadff3f6dc0952350bd39c9f17def50a0374ef47d6147ef', vendor_script) self.assertIn('dompurify@3.4.18', vendor_script) self.assertIn('8053ee2a6a09f9d50f7fcd6fb7f07072f52c7f3fa9aa12147cab4feaf65ee970', vendor_script) self.assertIn('@zip.js/zip.js@2.24.0/index.min.js', vendor_script) self.assertIn('6c13caf4b90e08323f404f596c51549cdc6b01010bd43935a0bdc6a25bd61021', vendor_script) self.assertIn('@zip.js/zip.js@2.25.0/LICENSE', vendor_script) self.assertIn('1b7ebc8d7889ed25491484ab2b102370742ca6c0b26650a0c62cc2269b579b84', vendor_script) self.assertIn('@zip.js/zip.js@2.25.0/index.min.js', vendor_script) self.assertIn('715a4067bb71d750d4af8e60390e48894072f65501e0442e53f252cbfc45cfbc', vendor_script) self.assertNotIn('writeFileSync(join(output, target))', vendor_script) for path in ('/static/vendor/pdf.min.mjs', '/static/vendor/pdf.worker.min.mjs', '/static/vendor/epub.min.js', '/static/vendor/marked.min.js', '/static/vendor/purify.min.js'): self.assertNotIn(path, self.sw)101 unmodified lines def test_docker_build_minifies_static_assets_without_node_in_runtime(self): # Preserve CR and all other source bytes for the fail-closed parser. dockerfile = (ROOT / "Dockerfile").read_bytes().decode("utf-8") self.assertIn("FROM node:26.11.1-bookworm-slim AS static-assets", dockerfile) self.assertIn("FROM node:26.13.1-bookworm-slim AS static-assets", dockerfile) self.assertIn("ARG ESBUILD_VERSION=0.28.2", dockerfile) self.assertIn("node /build/compose_app.mjs > /build/app-composed.js", dockerfile) self.assertIn("esbuild /build/app-composed.js --minify --target=es2020 --charset=utf8 --legal-comments=none", dockerfile)7 unmodified lines self.assertNotIn("COPY txt/ txt/", dockerfile) self.assertEqual(dockerfile.count("FROM node:"), 4) self.assertEqual(dockerfile.count("FROM python:"), 3) self.assertIn("FROM node:26.11.1-bookworm-slim AS search-generation", dockerfile) self.assertIn("FROM node:26.13.1-bookworm-slim AS search-generation", dockerfile) self.assertIn("node /build/fetch_search_generation.mjs", dockerfile) self.assertIn("COPY --from=search-generation /selected/ /check/data/", dockerfile) self.assertIn('CMD ["sh", "/app/scripts/start_search.sh"]', dockerfile)5 unmodified lines self.assertIn(f'export const DEFAULT_GENERATION = "{pinned.group(1)}";', prepare) self.assertIn("/data", (ROOT / ".gitignore").read_text().splitlines()) self.assertIn("data", (ROOT / ".dockerignore").read_text().splitlines()) self.assertIn("FROM node:26.11.1-bookworm-slim AS source-check-node", dockerfile) node_stage = dockerfile.split("FROM node:26.11.1-bookworm-slim AS source-check-node", 1)[1].split("\nFROM ", 1)[0] self.assertIn("FROM node:26.13.1-bookworm-slim AS source-check-node", dockerfile) node_stage = dockerfile.split("FROM node:26.13.1-bookworm-slim AS source-check-node", 1)[1].split("\nFROM ", 1)[0] self.assertIn("COPY quality/ quality/", node_stage) self.assertIn("RUN npm run check:static", dockerfile) self.assertIn("RUN npx --no-install pyright --project pyrightconfig.json", dockerfile)4 unmodified lines self.assertTrue((ROOT / "config/types" / f"jsconfig.{config}.json").is_file()) self.assertIn("pyrightconfig.json pyrightconfig.strict.json", node_stage) self.assertIn("pip install --no-cache-dir -r requirements.txt", dockerfile) self.assertIn("FROM python:3.11.17-slim AS source-check-python", dockerfile) python_stage = dockerfile.split("FROM python:3.11.17-slim AS source-check-python", 1)[1].split("\nFROM ", 1)[0] self.assertIn("FROM python:3.15.2-slim-trixie AS source-check-python", dockerfile) python_stage = dockerfile.split("FROM python:3.15.2-slim-trixie AS source-check-python", 1)[1].split("\nFROM ", 1)[0] pinned = (ROOT / "config/dependencies/static-check.txt").read_text().splitlines() self.assertEqual(pinned, ["ruff==0.17.3", "coverage==7.17.0", "mutmut==3.8.1"]) self.assertEqual(pinned, ["ruff==0.17.5", "coverage==7.17.3", "mutmut==3.8.1"]) self.assertIn("COPY config/dependencies/static-check.txt config/dependencies/static-check.txt", python_stage) self.assertIn("RUN pip install --no-cache-dir -r config/dependencies/static-check.txt", python_stage) self.assertIn("tests.performance.test_search_compute_benchmark", python_stage)1 unmodified line python_stage.index("tests.performance.test_search_compute_benchmark")) assert_source_check_python_gate(self, dockerfile) self.assertIn("RUN python -B scripts/check_python_static.py", dockerfile) self.assertIn("FROM node:26.11.1-bookworm-slim AS static-gate-test", dockerfile) self.assertIn("FROM node:26.13.1-trixie-slim AS static-gate-test", dockerfile) self.assertIn("COPY scripts/ scripts/", node_stage) self.assertIn("COPY tests/ tests/", node_stage) self.assertNotIn("COPY run_static_gate_shards.py", node_stage)24 unmodified lines self.assertIn("node scripts/reader/check_reader_text_coverage.mjs", dockerfile) def reader_v3_gates_reachable(text): stages = re.split(r'(?m)^FROM ', text) static_gate = [part for part in stages if part.startswith('node:26.11.1-bookworm-slim AS static-gate-test\n')] assets = [part for part in stages if part.startswith('node:26.11.1-bookworm-slim AS static-assets\n')] static_gate = [part for part in stages if part.startswith('node:26.13.1-trixie-slim AS static-gate-test\n')] assets = [part for part in stages if part.startswith('node:26.13.1-bookworm-slim AS static-assets\n')] self.assertEqual(len(static_gate), 1) self.assertEqual(len(assets), 1) gate_stage, assets_stage = static_gate[0], assets[0]12 unmodified lines for old, new in ( (' && node scripts/reader/check_reader_v3_coverage.mjs \\\n', ' # node scripts/reader/check_reader_v3_coverage.mjs \\\n'), ('FROM node:26.11.1-bookworm-slim AS static-gate-test\n', 'FROM node:26.11.1-bookworm-slim AS other-gate-test\n'), ('FROM node:26.13.1-trixie-slim AS static-gate-test\n', 'FROM node:26.13.1-bookworm-slim AS other-gate-test\n'), ('COPY --from=static-gate-test /check/static-gate-test-ok /tmp/checked-static-gate-test-ok\n', ''), ): self.assertEqual(dockerfile.count(old), 1) with self.assertRaises((AssertionError, ValueError)): reader_v3_gates_reachable(dockerfile.replace(old, new)) static_gate = dockerfile.split("FROM node:26.11.1-bookworm-slim AS static-gate-test", 1)[1].split("\nFROM ", 1)[0] static_gate = dockerfile.split("FROM node:26.13.1-trixie-slim AS static-gate-test", 1)[1].split("\nFROM ", 1)[0] self.assertEqual(static_gate.count(" && node scripts/reader/check_pdf_prefetch_contracts.mjs \\\n"), 1) self.assertIn("node scripts/reader/check_pdf_book_client_coverage.mjs", dockerfile) self.assertIn("node scripts/reader/check_pdf_book_url_coverage.mjs", dockerfile)18 unmodified lines self.assertIn("node --test tests/search/baselines/test_search_response_validation_baseline.mjs", dockerfile) self.assertIn("node --test tests/search/baselines/test_search_stable_id_baseline.mjs", dockerfile) self.assertIn("COPY --from=source-check-node /check/ /check/", dockerfile) self.assertIn("COPY --from=source-check-python /usr/local/lib/python3.11/site-packages/ /tmp/python-static-tools/", dockerfile) self.assertIn("COPY --from=source-check-python /usr/local/bin/ruff /tmp/python-static-tools/bin/ruff", dockerfile) self.assertIn("COPY --from=source-check-python /usr/local/ /usr/local/", static_gate) self.assertNotIn("PYTHONPATH=/tmp/python-static-tools", static_gate) self.assertIn("libssl3t64", static_gate) self.assertIn("libreadline8t64", static_gate) abi_check = "RUN python3 -B -c 'import sys, bz2, ctypes, lzma, sqlite3, ssl, coverage; assert sys.version_info[:3] == (3, 15, 2)'" self.assertIn(abi_check, static_gate) self.assertLess(static_gate.index("COPY --from=source-check-python /usr/local/ /usr/local/"), static_gate.index(abi_check)) self.assertLess(static_gate.index(abi_check), static_gate.index("RUN npx --no-install pyright")) self.assertIn("COPY --from=static-gate-test /check/static-gate-test-ok /tmp/checked-static-gate-test-ok", dockerfile) self.assertIn("FROM python:3.11.17-slim AS search-index-build", dockerfile) self.assertIn("FROM python:3.15.2-slim-trixie AS search-index-build", dockerfile) self.assertIn("python scripts/build/build_search_index_native.py --output-dir /native", dockerfile) self.assertIn("FROM source-check-python AS search-index-verified", dockerfile) self.assertIn("tests.search.backend.test_wildcard_index_oracle.WildcardIndexOracleTests.test_generated_index_is_exact_for_metadata_fields", dockerfile) self.assertIn("tests.search.backend.test_wildcard_index_oracle.WildcardIndexOracleTests.test_semantically_changed_but_well_formed_indexes_fail_the_oracle", dockerfile) self.assertIn("tests.search.backend.test_wildcard_index_oracle.WildcardIndexOracleTests.test_unicode_engine_has_no_equivalents_for_accelerated_ranges", dockerfile) runtime = re.split(r'^FROM ', dockerfile, flags=re.M)[-1] self.assertTrue(runtime.startswith("python:3.11.17-slim\n")) self.assertTrue(runtime.startswith("python:3.15.2-slim-trixie\n")) self.assertNotIn("COPY quality/", runtime) self.assertNotIn("config/dependencies/static-check.txt", runtime) self.assertIn("COPY requirements.txt .", runtime)287 unmodified lines
def test_other_stages_and_fake_instructions_cannot_supply_the_run(self): disabled = self.replace_run("&& python -B -m unittest -v", "&& echo python -B -m unittest -v") marker = "FROM node:26.11.1-bookworm-slim AS static-gate-test\n" marker = "FROM node:26.13.1-trixie-slim AS static-gate-test\n" self.assert_rejected(self.replace_once(disabled, marker, marker + self.run_instruction + "\n")) self.assert_rejected("# escape=`\n" + self.dockerfile) self.assert_rejected("# syntax=example/custom\n" + self.dockerfile) self.assert_rejected("RUN <<EOF\n" + self.run_instruction + "\nEOF\n" + self.dockerfile) source = "FROM python:3.11.17-slim AS source-check-python\n" source = "FROM python:3.15.2-slim-trixie AS source-check-python\n" self.assert_rejected(self.replace_once(self.dockerfile, source, source + source))
def test_final_image_requires_verified_stage_not_a_decoy_copy(self): verified_from = "FROM source-check-python AS search-index-verified" self.assert_rejected(self.replace_once(self.dockerfile, verified_from, "FROM python:3.11.17-slim AS search-index-verified")) "FROM python:3.15.2-slim-trixie AS search-index-verified")) edge = "COPY --from=search-index-verified /check/data/ /app/data/\n" # An unconditional local COPY is not a cross-stage dependency, even if # the real-looking cross-stage COPY remains in an unused stage/comment. local_copy = self.replace_once(self.dockerfile, edge, "COPY data/ /app/data/\n# " + edge) self.assert_rejected(local_copy) runtime_from = "FROM python:3.11.17-slim\n\nWORKDIR /app\n" runtime_from = "FROM python:3.15.2-slim-trixie\n\nWORKDIR /app\n" decoy = "FROM source-check-node AS unused-decoy\n" + edge + "\n" + runtime_from self.assert_rejected(self.replace_once(local_copy, runtime_from, decoy)) # A former runtime stage, still containing an unconditional COPY, does # not make the subsequently appended final stage depend on the gate. self.assert_rejected(self.dockerfile + "\nFROM python:3.11.17-slim\nCOPY data/ /app/data/\n") self.assert_rejected(self.dockerfile + "\nFROM python:3.15.2-slim-trixie\nCOPY data/ /app/data/\n") self.assert_rejected(self.replace_once(self.dockerfile, edge, "# " + edge)) for old, new in ( ('RUN node /build/fetch_search_generation.mjs', 'RUN echo node /build/fetch_search_generation.mjs'),46 unmodified lines ) for index, dockerfile in enumerate(mutants): with self.subTest(mutant=index): stage = dockerfile.split("FROM python:3.11.17-slim AS source-check-python", 1)[1].split("\nFROM ", 1)[0] stage = dockerfile.split("FROM python:3.15.2-slim-trixie AS source-check-python", 1)[1].split("\nFROM ", 1)[0] self.assertIn(PYTHON_GATE_MODULES[2], stage) self.assertLess(stage.index("pip install --no-cache-dir -r requirements.txt"), stage.index(PYTHON_GATE_MODULES[2])) self.assert_full_contract_rejected(dockerfile)22 unmodified lines self.assert_full_contract_rejected(mutant, "unsupported Dockerfile control or whitespace")
def test_physical_lines_reject_other_instruction_decoys_in_full_contract(self): source = "FROM python:3.11.17-slim AS source-check-python" source = "FROM python:3.15.2-slim-trixie AS source-check-python" verified = "FROM source-check-python AS search-index-verified" copy_tests = "COPY tests/ tests/\n# Runtime import mounts" # Collapse continuations so Docker sees only one commented RUN line.Dockerfile+14-11
config/dependencies/static-check.txt+2-2
requirements.txt+2-2
static/reader-resources.js+3-3
tests/gates/test_static_contract.py+37-29