diff --git a/packages/experimental/cua/tests/fixtures/permission-store-worker.ts b/packages/experimental/cua/tests/fixtures/permission-store-worker.ts index a1b5f6d5ff..5a30c72de6 100644 --- a/packages/experimental/cua/tests/fixtures/permission-store-worker.ts +++ b/packages/experimental/cua/tests/fixtures/permission-store-worker.ts @@ -1,26 +1,16 @@ -/** Independent process used to verify fresh authorization reads over the production JSON backend. */ -import { Context } from '@deepseek-ai/cordis' -import Storage from '@deepseek-ai/dsh-storage' -import * as JsonStorage from '@deepseek-ai/dsh-storage-json' -import * as Domains from '@deepseek-ai/dsh-storage-domain' -import { CuaPermissionStore } from '../../src/permission-store.ts' -import type { CuaApplicationId } from '../../src/application-types.ts' +/** External file writer used to verify that an open provider reloads durable authorization. */ +import { readFile, rename, writeFile } from 'node:fs/promises' -const [root, directory, id] = process.argv.slice(2) -if (!root || !directory || !id) throw new Error('Expected storage root, profile directory and application id') -const ctx = new Context() -try { - ctx.provide('profileContext', { dir: directory }) - await ctx.plugin(Storage) - await ctx.plugin(JsonStorage, { root }) - await ctx.plugin(Domains, { backend: 'json' }) - const store = new CuaPermissionStore(ctx, [], 30_000) - await store.withState(new AbortController().signal, async (transaction) => { - const existing = transaction.state.applications[id] - await transaction.save({ ...transaction.state, applications: { ...transaction.state.applications, - [id]: { revoked: (existing?.revoked ?? 0) + 1, sessions: {}, - always: { id: id as CuaApplicationId, name: 'Other process', executablePath: '/other' } }, - } }) - }) - process.stdout.write('saved\n') -} finally { await ctx.fiber.dispose() } +const [file, id] = process.argv.slice(2) +if (!file || !id) throw new Error('Expected storage file and application id') +const record = JSON.parse(await readFile(file, 'utf8')) +const existing = record.global.applications[id] +record.global.applications[id] = { + revoked: (existing?.revoked ?? 0) + 1, + sessions: {}, + always: { id, name: 'Other process', executablePath: '/other' }, +} +const temporary = `${file}.writer-${process.pid}` +await writeFile(temporary, JSON.stringify(record)) +await rename(temporary, file) +process.stdout.write('saved\n') diff --git a/packages/experimental/cua/tests/permission-store.spec.ts b/packages/experimental/cua/tests/permission-store.spec.ts index 9f0e176259..4d8c8418d3 100644 --- a/packages/experimental/cua/tests/permission-store.spec.ts +++ b/packages/experimental/cua/tests/permission-store.spec.ts @@ -77,8 +77,9 @@ it('reloads another process’s writes instead of reusing an in-memory authoriza const f = await setup(), a = await f.open(f.directory, [grant]) await a.store.withState(signal, transaction => transaction.state) const controller = new AbortController() - const running = promisify(execFile)(process.execPath, ['--import', 'tsx/esm', - fileURLToPath(new URL('./fixtures/permission-store-worker.ts', import.meta.url)), f.storageRoot, f.directory, grant.id, + const file = join(f.storageRoot, (await readdir(f.storageRoot))[0]!) + const running = promisify(execFile)(process.execPath, [ + fileURLToPath(new URL('./fixtures/permission-store-worker.ts', import.meta.url)), file, grant.id, ], { cwd: process.cwd(), env: { PATH: process.env.PATH }, signal: controller.signal }) onTestFinished(async () => { controller.abort(); await running.catch(() => {}) }) expect((await running).stdout).toBe('saved\n')