diff --git a/scripts/lib/module-layers.baseline.json b/scripts/lib/module-layers.baseline.json index c866c844a0..7ce583316c 100644 --- a/scripts/lib/module-layers.baseline.json +++ b/scripts/lib/module-layers.baseline.json @@ -9,6 +9,6 @@ ], "crossProvider": {}, "entry": { - "application -> desktop": 12 + "application -> desktop": 11 } } diff --git a/src/application/desktop/DesktopApplicationExport.ts b/src/application/desktop/DesktopApplicationExport.ts index 2e69d448f6..34e96530df 100644 --- a/src/application/desktop/DesktopApplicationExport.ts +++ b/src/application/desktop/DesktopApplicationExport.ts @@ -34,6 +34,7 @@ import { isWithinAny } from "../../domain/desktop/desktopStateDiff.js"; import type { HostIdentity } from "../../domain/desktop/hostIdentity.js"; import { scrubDconf } from "../../domain/desktop/seedScrub.js"; import { createEvidence, type Evidence } from "../../domain/evidence.js"; +import type { DesktopTaskReaderRunner } from "../../ports/DesktopTaskReader.js"; import type { JsonValue } from "../../domain/jsonValue.js"; import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js"; import { analysisErrorWithCancellation } from "../../domain/analysisErrorCancellation.js"; @@ -343,9 +344,14 @@ const NO_SCRUB: SeedScrubReport = { unscrubbed: [], }; +/** State readers plus the host task reader needed by exportDesktopApplication. */ +export interface DesktopExportReaders extends DesktopStateReaders { + readonly taskReader: DesktopTaskReaderRunner; +} + const runExport = async ( request: DesktopExportRequest, - readers: DesktopStateReaders, + readers: DesktopExportReaders, signal: AbortSignal | undefined, ) => { const { evidence, capture } = await readDesktopCapture( @@ -384,6 +390,7 @@ const runExport = async ( ends, identity, checkpoints, + taskReader: readers.taskReader, signal, }); const admitted = await admitDesktopTasks( @@ -567,7 +574,7 @@ const publishedExportFailure = ( /** Export one capture folder as an agentenv computer app bundle, reported as Evidence. */ export const exportDesktopApplication = async ( request: DesktopExportRequest, - readers: DesktopStateReaders, + readers: DesktopExportReaders, signal?: AbortSignal, ): Promise => { try { diff --git a/src/application/desktop/DesktopExportReaders.ts b/src/application/desktop/DesktopExportReaders.ts index 2524428ca3..316d78e6d1 100644 --- a/src/application/desktop/DesktopExportReaders.ts +++ b/src/application/desktop/DesktopExportReaders.ts @@ -14,7 +14,7 @@ import { type StateEnds, } from "../../domain/desktop/desktopState.js"; import type { HostIdentity } from "../../domain/desktop/hostIdentity.js"; -import { runReaderHere } from "../../desktop/TaskReaderProcess.js"; +import type { DesktopTaskReaderRunner } from "../../ports/DesktopTaskReader.js"; import { shippedSeedBytes, shippedSeedViews, @@ -40,6 +40,7 @@ export interface ReaderSources { readonly identity: HostIdentity; readonly maxBytes: number; readonly signal: AbortSignal | undefined; + readonly taskReader: DesktopTaskReaderRunner; /** The capture's checkpoint names, and the folder a build computer keeps a screenshot of each in, if any. */ readonly checkpoints: readonly string[]; readonly screens: string | undefined; @@ -105,7 +106,8 @@ const exportReaderViews = readerViewsOfBytes( readers, (reader) => readerFile(sources, content, reader.file, at), - (argv, timeoutS) => runReaderHere(argv, timeoutS, sources.signal), + (argv, timeoutS) => + sources.taskReader(argv, timeoutS, sources.signal), ), sources.maxBytes, ); diff --git a/src/application/desktop/DesktopTaskExport.test.ts b/src/application/desktop/DesktopTaskExport.test.ts index 4cda72255e..575f60a902 100644 --- a/src/application/desktop/DesktopTaskExport.test.ts +++ b/src/application/desktop/DesktopTaskExport.test.ts @@ -601,6 +601,73 @@ describe("exportDesktopApplication with a task's readers", () => { }); }); +describe("exportDesktopApplication taskReader port", () => { + it("calls the injected taskReader port with the command, timeout, and signal", async () => { + const scratch = await createTestTempDirectory("desktop-task-port-"); + const taskPath = join(scratch, "task.json"); + const directory = join(scratch, "bundle"); + const controller = new AbortController(); + const calls: Array<{ + readonly argv: readonly string[]; + readonly timeoutS: number; + readonly signal: AbortSignal | undefined; + }> = []; + await writeFile( + taskPath, + JSON.stringify( + readerTask(["version v2"], { + id: "version", + file: DATABASE, + argv: ["custom-reader", "{file}"], + output: "lines", + timeout_s: 7, + }), + ), + ); + + const result = await exportDesktopApplication( + { + capture: await writeCaptureFolder(capture()), + directory, + name: undefined, + tasks: [taskPath], + }, + { + ...readers, + taskReader: async (argv, timeoutS, signal) => { + calls.push({ argv, timeoutS, signal }); + return { + exit_code: 0, + stdout: `${JSON.stringify({ + view: { + format: "text", + view: { + lines: calls.length === 1 ? ["version v2"] : ["version v1"], + line_count: 1, + truncated: false, + }, + }, + })}\n`, + stderr: "", + timed_out: false, + }; + }, + }, + controller.signal, + ); + + if (result instanceof Error) throw result; + expect(calls).toHaveLength(2); + expect(calls.every((call) => call.timeoutS === 37)).toBe(true); + expect(calls.every((call) => call.signal === controller.signal)).toBe(true); + expect( + calls.every((call) => + call.argv.some((part) => part.includes("custom-reader")), + ), + ).toBe(true); + }); +}); + /** The notes capture with nothing changed between its checkpoints, as an app that keeps its state on screen leaves it. */ const screenOnlyCapture = () => { const base = capture(); diff --git a/src/application/desktop/desktopCapture.fixture.ts b/src/application/desktop/desktopCapture.fixture.ts index 5619bc05f6..7eb6ec59e4 100644 --- a/src/application/desktop/desktopCapture.fixture.ts +++ b/src/application/desktop/desktopCapture.fixture.ts @@ -6,7 +6,8 @@ import { join } from "node:path"; import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js"; import type { DesktopApplicationCapture } from "../../domain/desktop/desktopCapture.js"; import { createEvidence } from "../../domain/evidence.js"; -import type { DesktopStateReaders } from "./DesktopApplicationState.js"; +import { runDesktopTaskReader } from "../../desktop/DesktopCaptureProvider.js"; +import type { DesktopExportReaders } from "./DesktopApplicationExport.js"; import { DESKTOP_OPERATION, DESKTOP_PROVIDER, @@ -285,7 +286,7 @@ export const writeCaptureFolder = async ( }; /** A SQLite reader that reports one row per retained version's last byte. */ -export const readers: DesktopStateReaders = { +export const readers: DesktopExportReaders = { sqlite: async (database) => { // A staged write-ahead log, when present, decides the version instead. const log = await readFile(`${database}-wal`, "latin1").catch( @@ -313,4 +314,5 @@ export const readers: DesktopStateReaders = { }; }, dconf: async () => ({ ok: false, error: "unused" }), + taskReader: runDesktopTaskReader, }; diff --git a/src/cli/desktopCaptureCommands.ts b/src/cli/desktopCaptureCommands.ts index 210f95d2c2..598dd0096a 100644 --- a/src/cli/desktopCaptureCommands.ts +++ b/src/cli/desktopCaptureCommands.ts @@ -29,7 +29,10 @@ import { DESKTOP_CAPTURE_DEFAULTS, type DesktopCaptureProgress, } from "../domain/desktop/desktopCapture.js"; -import { createDesktopCaptureProvider } from "../desktop/DesktopCaptureProvider.js"; +import { + createDesktopCaptureProvider, + runDesktopTaskReader, +} from "../desktop/DesktopCaptureProvider.js"; import { SessionRequestQueue } from "../desktop/DesktopSessionRequests.js"; import { withCommandCancellation } from "./commandCancellation.js"; import { registerCliCommand } from "./commandRegistry.js"; @@ -407,7 +410,7 @@ const registerDesktopExportCommand = ( ...withheldRequestOf(options), viewPolicy: options.viewPolicy, }, - readers, + { ...readers, taskReader: runDesktopTaskReader }, signal, ), ); diff --git a/src/desktop/DesktopCaptureProvider.ts b/src/desktop/DesktopCaptureProvider.ts index 4ee67abaac..44285fef23 100644 --- a/src/desktop/DesktopCaptureProvider.ts +++ b/src/desktop/DesktopCaptureProvider.ts @@ -1,4 +1,5 @@ import type { DesktopCaptureProvider } from "../ports/DesktopApplicationSession.js"; +import type { DesktopTaskReaderRunner } from "../ports/DesktopTaskReader.js"; import { runDesktopSession, runningApplicationWindows, @@ -7,8 +8,12 @@ import { DesktopContentStore } from "./DesktopContentStore.js"; import { walkHomeState } from "./HomeStateWalker.js"; import { inspectLinuxApplication } from "./LinuxApplicationInventory.js"; import { resolveProgram } from "./ProgramLookup.js"; +import { runReaderHere } from "./TaskReaderProcess.js"; import { X11WindowObserver } from "./X11WindowObserver.js"; +/** Run one exported-task reader command using the desktop host runner. */ +export const runDesktopTaskReader: DesktopTaskReaderRunner = runReaderHere; + /** * The desktop provider's implementation of the capture port: `xprop` window * observation, the supervised session runner, the home-folder walker and the diff --git a/src/ports/DesktopTaskReader.ts b/src/ports/DesktopTaskReader.ts new file mode 100644 index 0000000000..bc61a29d85 --- /dev/null +++ b/src/ports/DesktopTaskReader.ts @@ -0,0 +1,8 @@ +import type { ReaderCommandResult } from "../domain/desktop/appTaskReaders.js"; + +/** Run one task file reader command against an extracted capture file on disk. */ +export type DesktopTaskReaderRunner = ( + argv: readonly string[], + timeoutS: number, + signal?: AbortSignal, +) => Promise;