vomebook commited on
Commit ·
fa4486f
1
Parent(s): 29078f2
Upgrade Space runtime and reader dependencies
Browse filesFiles changed (5)
1234567891011121312 unmodified lines2627282930313220 unmodified lines535455565758596061626364656667686945 unmodified lines11511611711811912012131 unmodified lines15315415515615715815913 unmodified lines173174175176177178179# 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-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-generationFROM node:26.11.1-bookworm-slim AS source-check-nodeWORKDIR /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.mjsFROM python:3.11.17-slim AS source-check-pythonWORKDIR /checkCOPY requirements.txt ruff.toml ./20 unmodified linestests.search.backend.test_search_runtime_entry \tests.search.backend.test_search_start_scriptFROM node:26.11.1-bookworm-slim AS static-gate-testWORKDIR /checkRUN apt-get update && apt-get install -y --no-install-recommends python3 \&& 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 ruff.toml ./COPY config/dependencies/static-check.txt config/dependencies/static-check.txtENV PYTHONPATH=/tmp/python-static-toolsRUN 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-okFROM node:26.11.1-bookworm-slim AS static-assetsARG 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 /outFROM python:3.11.17-slim AS search-index-buildWORKDIR /buildRUN apt-get update && apt-get install -y --no-install-recommends gcc libc6-dev \13 unmodified linestests.search.backend.test_wildcard_index_oracle.WildcardIndexOracleTests.test_unicode_engine_has_no_equivalents_for_accelerated_ranges \tests.data.test_generated_data_oracleFROM python:3.11.17-slimWORKDIR /app1234567891011121312 unmodified lines2627282930313220 unmodified lines535455565758596061626364656667686970717245 unmodified lines11811912012112212312431 unmodified lines15615715815916016116213 unmodified lines176177178179180181182# Pin the published generation for reproducible builds without build arguments.# An explicit SEARCH_DATA_GENERATION selects another immutable bucket generation.FROM 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-generationFROM node:26.13.1-bookworm-slim AS source-check-nodeWORKDIR /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.mjsFROM python:3.15.2-slim-trixie AS source-check-pythonWORKDIR /checkCOPY requirements.txt ruff.toml ./20 unmodified linestests.search.backend.test_search_runtime_entry \tests.search.backend.test_search_start_scriptFROM node:26.13.1-trixie-slim AS static-gate-testWORKDIR /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 \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/ /usr/local/COPY ruff.toml ./COPY config/dependencies/static-check.txt config/dependencies/static-check.txtRUN 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-okFROM node:26.13.1-bookworm-slim AS static-assetsARG 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 /outFROM python:3.15.2-slim-trixie AS search-index-buildWORKDIR /buildRUN apt-get update && apt-get install -y --no-install-recommends gcc libc6-dev \13 unmodified linestests.search.backend.test_wildcard_index_oracle.WildcardIndexOracleTests.test_unicode_engine_has_no_equivalents_for_accelerated_ranges \tests.data.test_generated_data_oracleFROM python:3.15.2-slim-trixieWORKDIR /app
123ruff==0.17.3coverage==7.17.0mutmut==3.8.1123ruff==0.17.5coverage==7.17.3mutmut==3.8.1
123456fastapi==0.162.0starlette==1.10.0pydantic==2.14.2uvicorn==0.54.0uvloop==0.23.0httptools==0.9.0123456fastapi==0.163.1starlette==1.10.0pydantic==2.14.3uvicorn==0.54.0uvloop==0.23.0httptools==0.9.0
78 unmodified lines798081828384853 unmodified lines89909192939495969778 unmodified linessha256: "0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551"},zipLicense: {url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.24.0/LICENSE",file: "LICENSE_zipjs",sha256: "1b7ebc8d7889ed25491484ab2b102370742ca6c0b26650a0c62cc2269b579b84"},3 unmodified linessha256: "b7ca4450b19559a1d50eb381adcee94b82449674be4cd17789d9beba7e6122a1"},zip: {url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.24.0/index.min.js",file: "zip.js",sha256: "6c13caf4b90e08323f404f596c51549cdc6b01010bd43935a0bdc6a25bd61021"},textLayer: {url: "https://cdn.jsdelivr.net/gh/mozilla/pdf.js@v6.5.438/web/text_layer_builder.css",78 unmodified lines798081828384853 unmodified lines89909192939495969778 unmodified linessha256: "0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551"},zipLicense: {url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.25.0/LICENSE",file: "LICENSE_zipjs",sha256: "1b7ebc8d7889ed25491484ab2b102370742ca6c0b26650a0c62cc2269b579b84"},3 unmodified linessha256: "b7ca4450b19559a1d50eb381adcee94b82449674be4cd17789d9beba7e6122a1"},zip: {url: "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.25.0/index.min.js",file: "zip.js",sha256: "715a4067bb71d750d4af8e60390e48894072f65501e0442e53f252cbfc45cfbc"},textLayer: {url: "https://cdn.jsdelivr.net/gh/mozilla/pdf.js@v6.5.438/web/text_layer_builder.css",
80 unmodified lines81828384858687888936 unmodified lines126127128129130131132532 unmodified lines665666667668669670671672101 unmodified lines7747757767777787797807 unmodified lines7887897907917927937945 unmodified lines8008018028038048058068074 unmodified lines8128138148158168178188198208211 unmodified line82382482582682782882924 unmodified lines85485585685785885986086112 unmodified lines87487587687787887988088188288388488588688718 unmodified lines906907908909910911912913914915916917918919920921922287 unmodified lines1210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123846 unmodified lines128512861287128812891290129122 unmodified lines131413151316131713181319132080 unmodified linessource_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[verified_index][0], ["source-check-python", "AS", "search-index-verified"])test.assertEqual(stages[-1][0], ["python:3.11.17-slim"], "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 linesgeneration = [(words, body) for words, body in stagesif 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"])pinned = "5c80388b465f35f74711c17aef9e31f8bb1c04fc0553e9820ac271658d740639"test.assertEqual([(op, tuple(value.split())) for op, value in generation[0][1]], [("ARG", (f"SEARCH_DATA_GENERATION={pinned}",)),532 unmodified linesself.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.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 linesdef 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("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 linesself.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("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 linesself.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("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 linesself.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]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.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 linepython_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("COPY scripts/ scripts/", node_stage)self.assertIn("COPY tests/ tests/", node_stage)self.assertNotIn("COPY run_static_gate_shards.py", node_stage)24 unmodified linesself.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')]self.assertEqual(len(static_gate), 1)self.assertEqual(len(assets), 1)gate_stage, assets_stage = static_gate[0], assets[0]12 unmodified linesfor 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'),('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]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 linesself.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=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("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.assertNotIn("COPY quality/", runtime)self.assertNotIn("config/dependencies/static-check.txt", runtime)self.assertIn("COPY requirements.txt .", runtime)287 unmodified linesdef 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"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"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"))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"decoy = "FROM source-check-node AS unused-decoy\n" + edge + "\n" + runtime_fromself.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.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]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 linesself.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"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.80 unmodified lines81828384858687888936 unmodified lines126127128129130131132532 unmodified lines665666667668669670671672673674101 unmodified lines7767777787797807817827 unmodified lines7907917927937947957965 unmodified lines8028038048058068078088094 unmodified lines8148158168178188198208218228231 unmodified line82582682782882983083124 unmodified lines85685785885986086186286312 unmodified lines87687787887988088188288388488588688788888918 unmodified lines908909910911912913914915916917918919920921922923924925926927928929930287 unmodified lines1218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124646 unmodified lines129312941295129612971298129922 unmodified lines132213231324132513261327132880 unmodified linessource_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.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.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 linesgeneration = [(words, body) for words, body in stagesif len(words) == 3 and words[2] == "search-generation"]test.assertEqual(len(generation), 1)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 linesself.assertIn('392f4df89533b50f1dadff3f6dc0952350bd39c9f17def50a0374ef47d6147ef', vendor_script)self.assertIn('dompurify@3.4.18', vendor_script)self.assertIn('8053ee2a6a09f9d50f7fcd6fb7f07072f52c7f3fa9aa12147cab4feaf65ee970', 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 linesdef 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.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 linesself.assertNotIn("COPY txt/ txt/", dockerfile)self.assertEqual(dockerfile.count("FROM node:"), 4)self.assertEqual(dockerfile.count("FROM python:"), 3)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 linesself.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.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 linesself.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.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.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 linepython_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.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 linesself.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.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 linesfor old, new in ((' && node scripts/reader/check_reader_v3_coverage.mjs \\\n',' # node scripts/reader/check_reader_v3_coverage.mjs \\\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.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 linesself.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/ /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.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.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 linesdef 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.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.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.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.15.2-slim-trixie\n\nWORKDIR /app\n"decoy = "FROM source-check-node AS unused-decoy\n" + edge + "\n" + runtime_fromself.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.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.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 linesself.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.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