Repository navigation
feat(host): capture HostEnvironment once at entry points #3763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+5,324
−1,820
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
77dde28
feat(host): capture HostEnvironment once at entry points
thymikee f4d4970
fix(host): resolve relative state dirs against the captured working d…
thymikee 2ebb886
fix(host): give platform code the command host instead of process reads
thymikee 5effcd7
fix(host): answer review of the host environment foundation
thymikee ae204b4
fix(host): keep the test host setup out of mutation scope and finish …
thymikee fb9e4e6
fix(host): bind the test command host per suite, not globally
thymikee 30bbef5
chore(deps): declare test-kit in the HarmonyOS and Linux platform pac…
thymikee d522d25
fix(host): bind the test command host in the stale-provider admission…
thymikee 756cf4e
fix(host): resolve every client read from the client's host
thymikee 63b984b
fix(host): resolve the daemon policy path against the host working di…
thymikee f4616b9
style: format the daemon policy reuse test
thymikee 2a6416d
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee 7c68072
test: merge the duplicate test-kit import in the handler chain routin…
thymikee 3c622c3
fix(host): start a launched daemon in the launching host's working di…
thymikee ab5ee6e
test: keep the registration-owner test under its size ratchet
thymikee d1ab624
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee 665af8a
test: merge the duplicate test-kit import in the stale provider admis…
thymikee 7eb7379
refactor(daemon): read configuration from the request host instead of…
thymikee 225e0bd
fix(daemon): drop the unused host from install-from-source and tighte…
thymikee 5816abe
refactor(cli): resolve one transport per run and one host per MCP too…
thymikee 916db0b
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee 9a4e081
test: pin the one-transport CLI run and one-host MCP call; document t…
thymikee f744554
test: keep the failure that explains a missed materialization in the …
thymikee c9aa2f2
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee 326a9ef
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee acc42ba
refactor(daemon): read the host cwd where the deploy handlers use it,…
thymikee db55a5d
test: give the iOS recording scenario's daemon host the PATH and Swif…
thymikee ede74e1
test: fail the transport test on an unexpected exit or throw and alwa…
thymikee e2e3dc7
test: keep the scenario harness's state dir and transport out of reac…
thymikee ab7aad0
Merge remote-tracking branch 'origin/main' into tmp/hostenv-merge
thymikee d8a9bd4
fix(daemon): abandon a transient device claim under the same env that…
thymikee 597f793
refactor(host): read host settings from HostEnvironment in root src a…
thymikee 870cf66
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee 9f3e58f
test: build the scenario gateway on the daemon host's env and pin the…
thymikee 779dcab
test: say which package still reads PATH from the process in the reco…
thymikee cb17bb3
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee 9c1e9ec
refactor(platforms): read host settings from HostEnvironment in platf…
thymikee 521ccb5
Merge remote-tracking branch 'origin/main' into refactor/host-environ…
thymikee fab82cc
test: pass the host to the iOS e2e live runner's request
thymikee 4f6dd3e
refactor(react-native): drop the redundant outer catch around the sco…
thymikee 595fa48
refactor(capture-kit): report an unavailable PNG worker in every scop…
thymikee d1f3001
refactor(capture-kit): report each PNG worker transition to unavailab…
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { captureHostEnvironment } from '@agent-device/host-kit/process'; | ||
| import type { HostEnvironment } from '@agent-device/kernel/source-value'; | ||
|
|
||
| /** | ||
| * The host a capture-kit test hands to code that takes one explicitly: a snapshot of the process | ||
| * as it is when called, so `vi.stubEnv` made earlier in the test reaches it. Test-kit depends on | ||
| * capture-kit, so capture-kit keeps this local. | ||
| */ | ||
| export function createTestHost(): HostEnvironment { | ||
| return captureHostEnvironment(process); | ||
| } |
57 changes: 57 additions & 0 deletions
57
packages/capture-kit/src/png-worker-client-unavailable.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { EventEmitter } from 'node:events'; | ||
| import { expect, test, vi } from 'vitest'; | ||
| import { PNG } from './png.ts'; | ||
|
|
||
| test('a worker whose entry is missing is reported once and later registrations hear it', async () => { | ||
| vi.resetModules(); | ||
| vi.doMock('./internal-entry.ts', () => ({ resolveInternalEntryModulePath: () => null })); | ||
| const { decodePngAsync, prewarmPngWorker } = await import('./png-worker-client.ts'); | ||
| const png = PNG.sync.write(new PNG({ width: 1, height: 1 })); | ||
| const first = vi.fn(); | ||
| const second = vi.fn(); | ||
|
|
||
| prewarmPngWorker(first); | ||
| const decoded = await decodePngAsync(png, 'fallback'); | ||
| prewarmPngWorker(second); | ||
|
|
||
| expect(decoded.width).toBe(1); | ||
| expect(first.mock.calls).toEqual([[{ kind: 'entry-not-found' }]]); | ||
| expect(second.mock.calls).toEqual([[{ kind: 'entry-not-found' }]]); | ||
| vi.doUnmock('./internal-entry.ts'); | ||
| }); | ||
|
|
||
| test('a worker that dies after it started is reported once, and its pending job still completes', async () => { | ||
| vi.resetModules(); | ||
| class FakeWorker extends EventEmitter { | ||
| static last: FakeWorker | undefined; | ||
| constructor() { | ||
| super(); | ||
| FakeWorker.last = this; | ||
| } | ||
| postMessage(): void {} | ||
| ref(): void {} | ||
| unref(): void {} | ||
| terminate(): Promise<number> { | ||
| return Promise.resolve(0); | ||
| } | ||
| } | ||
| vi.doMock('node:worker_threads', async (importOriginal) => ({ | ||
| ...(await importOriginal<typeof import('node:worker_threads')>()), | ||
| Worker: FakeWorker, | ||
| })); | ||
| const { decodePngAsync, prewarmPngWorker } = await import('./png-worker-client.ts'); | ||
| const png = PNG.sync.write(new PNG({ width: 1, height: 1 })); | ||
| const unavailable = vi.fn(); | ||
| prewarmPngWorker(unavailable); | ||
| expect(unavailable).not.toHaveBeenCalled(); | ||
|
|
||
| const decoded = decodePngAsync(png, 'under-request'); | ||
| const worker = FakeWorker.last; | ||
| if (!worker) throw new Error('the pre-warm did not start a worker'); | ||
| worker.emit('error', new Error('worker crashed')); | ||
| worker.emit('exit', 1); | ||
|
|
||
| expect((await decoded).width).toBe(1); | ||
| expect(unavailable.mock.calls).toEqual([[{ kind: 'worker-error', detail: 'worker crashed' }]]); | ||
| vi.doUnmock('node:worker_threads'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/capture-kit/src/recording/__tests__/overlay-script-paths.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test, vi } from 'vitest'; | ||
| import { mkdtempForTestSync } from '../../tmp-dir.fixtures.ts'; | ||
|
|
||
| vi.mock('@agent-device/host-kit/command', async () => { | ||
| const fs = await import('node:fs'); | ||
| return { | ||
| runCmd: vi.fn(async (_cmd: string, args: string[]) => { | ||
| fs.writeFileSync(args[args.indexOf('--output') + 1]!, 'processed'); | ||
| return { stdout: '', stderr: '', exitCode: 0 }; | ||
| }), | ||
| }; | ||
| }); | ||
| vi.mock('../video.ts', () => ({ waitForPlayableVideo: vi.fn(async () => {}) })); | ||
| vi.mock('../swift-cache.ts', () => ({ | ||
| buildSwiftToolEnv: () => ({}), | ||
| compileSwiftSourceFile: vi.fn(async () => '/bin/true'), | ||
| resolveRecordingScriptPath: vi.fn( | ||
| (name: string, _projectRoot: string, cwd: string) => `${cwd}/${name}`, | ||
| ), | ||
| })); | ||
|
|
||
| import { overlayRecordingTouches, startRecordingOverlayBudget } from '../overlay.ts'; | ||
| import { compileSwiftSourceFile } from '../swift-cache.ts'; | ||
|
|
||
| test('a helper script path is resolved per host working directory, not once per process', async () => { | ||
| const root = mkdtempForTestSync('agent-device-overlay-script-paths-'); | ||
| const videoPath = path.join(root, 'recording.mp4'); | ||
| const telemetryPath = path.join(root, 'recording.gesture-telemetry.json'); | ||
| fs.writeFileSync(telemetryPath, '{"events":[]}'); | ||
| const overlay = async (cwd: string) => { | ||
| fs.writeFileSync(videoPath, 'original'); | ||
| await overlayRecordingTouches({ | ||
| host: { env: {}, cwd }, | ||
| videoPath, | ||
| telemetryPath, | ||
| deadline: startRecordingOverlayBudget(), | ||
| }); | ||
| }; | ||
|
|
||
| await overlay('/cwd/one'); | ||
| await overlay('/cwd/two'); | ||
| await overlay('/cwd/one'); | ||
|
|
||
| expect(vi.mocked(compileSwiftSourceFile).mock.calls.map(([params]) => params.sourcePath)).toEqual( | ||
| [ | ||
| '/cwd/one/recording-overlay.swift', | ||
| '/cwd/two/recording-overlay.swift', | ||
| '/cwd/one/recording-overlay.swift', | ||
| ], | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
reportUnavailablesurvivesterminatePngWorker(), so a later worker created after daemon shutdown can report failures into the old daemon'slogPath. Clear the sink during termination before allowing the module to respawn a worker.Prompt for AI agents