Skip to content

The agent that grows with you

test: finish image and freshness coverage transfers

ethernet0449cf110cbf
diff --git a/tests-js/product-builders.test.mjs b/tests-js/product-builders.test.mjs
index 0c01b96fea6..4ad12cf4600 100644
--- a/tests-js/product-builders.test.mjs
+++ b/tests-js/product-builders.test.mjs
@@ -1,5 +1,5 @@
import { execFileSync } from 'node:child_process'
-import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync, symlinkSync } from 'node:fs'
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync, symlinkSync, statSync, utimesSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { createRequire } from 'node:module'
@@ -288,9 +288,29 @@ test('TUI freshness invalidates source, configuration and compiler inputs and da
put(source, 'ui-tui/src/value.ts', 'export const value: string = "shared source";')
put(source, 'apps/shared/src/value.ts', 'export { value } from "../../../ui-tui/src/value";')
put(source, 'ui-tui/src/entry.tsx', 'import { value } from "../../apps/shared/src/value"; console.log(value);')
+ put(source, 'package-lock.json', '{"lockfileVersion":3}')
+ const preservedTimes = new Date('2020-01-01T00:00:00Z')
+ const sameLengthChanges = [
+ ['ui-tui/src/value.ts', 'shared', 'edited'],
+ ['apps/shared/src/value.ts', 'value', 'VALUE'],
+ ['package.json', 'true', 'null'],
+ ['package-lock.json', ':3', ':2'],
+ ]
+ for (const [name] of sameLengthChanges) utimesSync(path.join(source, name), preservedTimes, preservedTimes)
await buildTui({ source, out })
const current = () => productCurrent({ source, product: 'tui', out: path.join(out, 'dist') })
expect(current()).toBe(true)
+ for (const [name, from, to] of sameLengthChanges) {
+ const file = path.join(source, name), previous = readFileSync(file, 'utf8'), before = statSync(file)
+ expect(previous).toContain(from)
+ writeFileSync(file, previous.replace(from, to))
+ utimesSync(file, preservedTimes, preservedTimes)
+ expect([statSync(file).size, statSync(file).mtimeMs]).toEqual([before.size, before.mtimeMs])
+ expect(current(), `same-size and same-mtime change in ${name}`).toBe(false)
+ writeFileSync(file, previous)
+ utimesSync(file, preservedTimes, preservedTimes)
+ expect(current(), `restored ${name}`).toBe(true)
+ }
for (const name of [
'ui-tui/src/value.ts', 'apps/shared/src/value.ts',
'ui-tui/packages/hermes-ink/src/entry-exports.ts',
diff --git a/tests/docker/test_immutable_install.py b/tests/docker/test_immutable_install.py
index e2fae89e08a..824eab3ce91 100644
--- a/tests/docker/test_immutable_install.py
+++ b/tests/docker/test_immutable_install.py
@@ -29,6 +29,27 @@ def test_install_tree_not_writable_by_hermes(
"""
start_container(built_image, container_name)
+ probe = docker_exec(container_name, "/opt/hermes/.venv/bin/python", "-c", """
+import os
+from pathlib import Path
+from hermes_cli.config import detect_install_method
+assert os.geteuid() != 0
+code = Path('/opt/hermes/.install_method')
+home = Path('/opt/data/.install_method')
+assert code.read_text().strip() == 'docker'
+assert detect_install_method(Path('/opt/hermes')) == 'docker'
+assert not home.exists() or home.read_text().strip() != 'docker'
+try:
+ with code.open('a'):
+ pass
+except PermissionError:
+ pass
+else:
+ raise AssertionError('runtime user can alter installation method')
+assert code.read_text().strip() == 'docker'
+""")
+ assert probe.returncode == 0, probe.stdout + probe.stderr
+
r = docker_exec_sh(
container_name,
# Try to create a file under /opt/hermes as the hermes user
diff --git a/tests/hermes_cli/test_tui_npm_install.py b/tests/hermes_cli/test_tui_npm_install.py
index 58b20546c4c..bebce4d6fdf 100644
--- a/tests/hermes_cli/test_tui_npm_install.py
+++ b/tests/hermes_cli/test_tui_npm_install.py
@@ -166,21 +166,3 @@ def test_tui_rebuild_preserves_the_prepared_desktop_and_web_union(tui_source):
assert acquired == ["npm", "npm"]
assert (root / "node_modules/web").exists()
assert (root / "node_modules/apps-desktop").exists()
-
-
[email protected]("changed", ["ui-tui/src/entry.tsx", "package.json", "package-lock.json", "apps/shared/shared.ts"])
-def test_tui_rebuild_tracks_root_and_shared_inputs(tui_source, changed):
- root, _ = tui_source
- tui = root / "ui-tui"
- changed_file = root / changed
- changed_file.parent.mkdir(parents=True, exist_ok=True)
- if not changed_file.exists():
- changed_file.write_text("original input\n", encoding="utf-8")
- main_tui_launch._make_tui_argv(tui, tui_dev=False)
- assert not main_tui_launch._tui_need_rebuild(tui), "must have a current receipt before invalidation"
- before = changed_file.stat()
- changed_file.write_text(changed_file.read_text(encoding="utf-8") + "\n", encoding="utf-8")
- # A content change must invalidate even when mtimes are restored.
- os.utime(changed_file, ns=(before.st_atime_ns, before.st_mtime_ns))
- assert main_tui_launch._tui_need_rebuild(tui)
diff --git a/tests/tools/test_dockerfile_immutable_install.py b/tests/tools/test_dockerfile_immutable_install.py
deleted file mode 100644
index 41f5e74ac50..00000000000
--- a/tests/tools/test_dockerfile_immutable_install.py
+++ /dev/null
@@ -1,61 +0,0 @@
-"""Packaging guards not yet covered by the image-runtime suite.
-
-Write permissions and lazy-install policy are exercised by tests/docker.
-Keep stamp placement and Photon preparation until those image checks exist.
-"""
-from __future__ import annotations
-
-import re
-from pathlib import Path
-
-REPO_ROOT = Path(__file__).resolve().parents[2]
-DOCKERFILE = REPO_ROOT / "Dockerfile"
-
-
-def _dockerfile_text() -> str:
- return DOCKERFILE.read_text()
-
-
-def test_dockerfile_bakes_code_scoped_install_method_stamp() -> None:
- """The 'docker' install-method stamp is baked next to the code.
-
- detect_install_method() reads the code-scoped stamp
- (/opt/hermes/.install_method) first; baking it at build time keeps the
- published image self-identifying as 'docker' WITHOUT writing into the
- shared $HERMES_HOME data volume (which a host install may also use).
- The stamp is created by root in the shim-wiring RUN block; the hermes
- user can't modify it (go-w from the --chmod on the source COPY).
- """
- text = _dockerfile_text()
- assert "printf 'docker\\n' > /opt/hermes/.install_method" in text
-
- # The stamp must be in the RUN block that wires the exec shim.
- shim_block = re.search(
- r"RUN mkdir -p /opt/hermes/bin && \\\n"
- r"(?:.*\\\n)+?"
- r"\s+printf 'docker\\n' > /opt/hermes/\.install_method",
- text,
- )
- assert shim_block, "install-method stamp must be in the shim-wiring RUN block"
-
-
-def test_dockerfile_bakes_photon_sidecar_deps() -> None:
- """The Photon sidecar's node_modules must be baked at build time (NS-606).
-
- The install tree is immutable at runtime, so a lazy `npm ci` on first
- connect would hit EROFS. Baking the deps (from the committed lockfile,
- which also runs the spectrum-ts postinstall patch) makes the hosted
- happy path install-free. Guards the contract between the Dockerfile
- and plugins/platforms/photon/sidecar_paths.resolve_sidecar_dir, which
- runs in place only when the baked deps exist and match the lockfile.
- """
- text = _dockerfile_text()
-
- assert "plugins/platforms/photon/sidecar/package-lock.json" in text
- assert re.search(
- r"RUN cd plugins/platforms/photon/sidecar && \\\n\s+npm ci", text
- ), "sidecar deps must be installed with `npm ci` (deterministic, runs postinstall patch)"
- # Immutability contract: never chown the sidecar tree to the runtime user.
- assert not re.search(
- r"chown\s+-R\s+hermes:hermes\s+/opt/hermes/plugins", text
- )