The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: grant the app-report waiver only to a listener proven to be the app's child
Tekniume4f862b7ca3d
diff --git a/tests-js/scripts/desktop-smoke-process.ts b/tests-js/scripts/desktop-smoke-process.tsindex 61e9cd495fc..67912fa2454 100644--- a/tests-js/scripts/desktop-smoke-process.ts+++ b/tests-js/scripts/desktop-smoke-process.ts@@ -14,7 +14,6 @@ export interface NativeProcess {parentPid: numberexecutable: stringcommand: string- ownership?: 'child' | 'host-ledger'sourceRoot?: string// The app binds its backend to a tree by environment, not only by argv: the// installation root leads PYTHONPATH and VIRTUAL_ENV names the venv. Only the@@ -24,6 +23,11 @@ export interface NativeProcess {cwd?: string}+/** The identified listener, with how it was tied to this app (ancestry or this home's ledger). */+export interface BackendProcess extends NativeProcess {+ ownership: 'child' | 'host-ledger'+}+/** What the caller already knows about the app that owns this listener. */export interface OriginEvidence {/** The root the app itself reported resolving, from its own UI/identity channel. */@@ -178,7 +182,7 @@ function processStartTime(pid: number): number | null {}/** Identify the actual listener, not a healthy helper or a command recorded before spawn. */-export function localBackendProcess(port: number, electronPid: number, hermesHome?: string): NativeProcess {+export function localBackendProcess(port: number, electronPid: number, hermesHome?: string): BackendProcess {if (!Number.isInteger(port) || port <= 0 || port > 65535) {throw new Error('Invalid backend port')}@@ -235,8 +239,7 @@ export function localBackendProcess(port: number, electronPid: number, hermesHomthrow new Error(`Expected one Desktop-owned or registered host backend listener on port ${port}; found ${matches.length}`)}- const backend = matches[0]- backend.ownership = children.includes(backend) ? 'child' : 'host-ledger'+ const backend: BackendProcess = { ...matches[0], ownership: children.includes(matches[0]) ? 'child' : 'host-ledger' }if (process.platform === 'linux') {backend.executable = fs.readlinkSync(`/proc/${backend.pid}/exe`)@@ -265,16 +268,16 @@ export function localBackendProcess(port: number, electronPid: number, hermesHom// host backend is not tied to this app by ancestry, so the app's report says nothing// about it; it must carry its own argv/env/cwd evidence. Requiring the process// evidence to be absent keeps this from loosening a platform that can read one.-function appVouchesForBackend(backend: NativeProcess, evidence: OriginEvidence,+function appVouchesForBackend(backend: BackendProcess, evidence: OriginEvidence,sameTree: (value?: string) => boolean): boolean {const processEvidenceUnreadable = backend.cwd === undefined&& backend.pythonPath === undefined && backend.virtualEnv === undefined- return processEvidenceUnreadable && backend.ownership !== 'host-ledger'+ return processEvidenceUnreadable && backend.ownership === 'child'&& evidence.appReportedRoot !== undefined && sameTree(evidence.appReportedRoot)}-export function assertBackendOrigin(backend: NativeProcess, root: string, origin: 'source' | 'bundled',+export function assertBackendOrigin(backend: BackendProcess, root: string, origin: 'source' | 'bundled',evidence: OriginEvidence = {}): void {if (origin === 'bundled') {if (path.basename(root) !== 'agent-payload' || !within(root, backend.executable)) {diff --git a/tests-js/scripts/desktop-smoke.test.ts b/tests-js/scripts/desktop-smoke.test.tsindex abc5d532785..cbfa00f5972 100644--- a/tests-js/scripts/desktop-smoke.test.ts+++ b/tests-js/scripts/desktop-smoke.test.ts@@ -230,7 +230,7 @@ test('a backend bound to the tree by environment needs no root in argv', (): voiconst interpreter = path.join(home, 'python3.11')fs.symlinkSync(resolvedPython, interpreter)- const base = { pid: process.pid, parentPid: 1, executable: interpreter, cwd: home,+ const base = { pid: process.pid, parentPid: 1, executable: interpreter, cwd: home, ownership: 'child' as const,command: `"${resolvedPython}" "-m" "hermes_cli.main" serve --host 127.0.0.1 --port 0` }// Control: with no environment evidence this is still a different tree.@@ -268,6 +268,7 @@ test('a platform that cannot read the backend environment proves ownership by thparentPid: 1,executable: path.join(home, 'python.exe'),command: `"${path.join(home, 'python.exe')}" "-m" "hermes_cli.main" serve --host 127.0.0.1 --port 0`,+ ownership: 'child' as const,}// Control row: with nothing readable and no report from the app, this is still a@@ -295,6 +296,11 @@ test('a platform that cannot read the backend environment proves ownership by thexpect((): void => {assertBackendOrigin({ ...backend, ownership: 'child' }, root, 'source', { appReportedRoot: root })}).not.toThrow()+ // Ancestry is the waiver's premise, so it must be stated, not inferred from an+ // absent field: a backend whose ownership was never established gets no waiver.+ expect((): void => {+ assertBackendOrigin({ ...backend, ownership: undefined } as unknown as typeof backend, root, 'source', { appReportedRoot: root })+ }).toThrow('source tree')} finally { fs.rmSync(home, { recursive: true, force: true }) }})@@ -307,7 +313,8 @@ test('OLD update-window source provenance carries its verified app identity to tfs.mkdirSync(root, { recursive: true })fs.mkdirSync(other, { recursive: true })- const backend = { pid: 2, parentPid: 1, executable: path.join(home, 'python.exe'),+ // As `localBackendProcess` reports a listener that descends from the app.+ const backend = { pid: 2, parentPid: 1, executable: path.join(home, 'python.exe'), ownership: 'child',command: `"${path.join(home, 'python.exe')}" -m hermes_cli.main dashboard --port 0` }expect((): void => {@@ -384,7 +391,7 @@ test('a module launch proves its tree without leaning on the app-owned cwd', ():const python = path.join(root, 'venv', 'bin', 'python')const launched = (executable: string, command: string): Parameters<typeof assertBackendOrigin>[0] =>- ({ pid: 1, parentPid: 1, executable, command, cwd: path.join(os.tmpdir(), 'app-owned-cwd') })+ ({ pid: 1, parentPid: 1, executable, command, cwd: path.join(os.tmpdir(), 'app-owned-cwd'), ownership: 'child' })const venv = launched(python, `"${python}" "-m" "hermes_cli.main" "serve" --host 127.0.0.1 --port 0`)// The app owns the backend's cwd; the installation's own venv interpreter is the evidence.