diff --git a/apps/web/tests/fixtures/time-context-every-step.patch.yml b/apps/web/tests/fixtures/time-context-every-step.patch.yml deleted file mode 100644 index dcff9f2b61..0000000000 --- a/apps/web/tests/fixtures/time-context-every-step.patch.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Browser-zone assertions need a fresh reading after the non-browser preparation turn. -- id: time-context - disabled: false - config: - refreshIntervalMs: 0 -- id: schedule - disabled: false -- id: ui-schedule - disabled: false diff --git a/apps/web/tests/schedule-after.e2e.ts b/apps/web/tests/schedule-after.e2e.ts index 84cd580b8b..76f82b1a8e 100644 --- a/apps/web/tests/schedule-after.e2e.ts +++ b/apps/web/tests/schedule-after.e2e.ts @@ -1,13 +1,16 @@ /** Keyless assembled-Web evidence for conversational Schedule delivery. */ -import { mkdir, readFile, writeFile } from 'node:fs/promises' +import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { join } from 'node:path' import { readFileSync } from 'node:fs' +import { tmpdir } from 'node:os' import { fileURLToPath } from 'node:url' import type { Browser, Page } from 'playwright' import { chromium } from 'playwright' +import { dump } from 'js-yaml' import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest' import type { Agent, AgentHandle } from '@deepseek-ai/dsh-agent' +import { entryListSchema } from '@deepseek-ai/cordis-plugin-include' import { bundlePatchPaths, composeEntries, loadOverlayPatches } from '@deepseek-ai/dsh-app-boot' import { MessageId, ToolCallId, createUserMessage, LlmAdapter } from '@deepseek-ai/dsh-llm' import { appendDelivery } from '../../../packages/schedule/schedule/src/delivery-history.ts' @@ -70,6 +73,45 @@ const CATALOG_EXPECTED = join(CATALOG_SNAPSHOT_DIR, 'catalog.expected.md') const BASE_PATCH = fileURLToPath(new URL('../../../packages/bundle/base/cordis.patch.yml', import.meta.url)) const WEB_BUNDLE = fileURLToPath(new URL('../../../packages/bundle/web-app/', import.meta.url)) const WEB_PATCHES = bundlePatchPaths(WEB_BUNDLE, (JSON.parse(readFileSync(join(WEB_BUNDLE, 'package.json'), 'utf8')) as { dsh: { bundle: { patch: string[] } } }).dsh.bundle) + +/** + * Write the overlay that enables the reminder stack for a Schedule scenario. + * + * The shipped bundle disables the Schedule service and the clock, and the two + * reminder rows live inside `preset-standard`; a top-level patch reaches only + * ids in the loaded entry list or a group's children, so it cannot target a + * plugin a preset declares. The overlay therefore restates the shipped + * `preset-standard` row beside the Host row enables, keeping the scenario on + * the shipped composition. + * @param dir - Directory that receives the overlay file. + * @returns Absolute path of the written overlay. + */ +async function writeReminderOverlay(dir: string): Promise { + const layers = [ + loadOverlayPatches('Schedule Web every-step overlay', BASE_PATCH), + ...WEB_PATCHES.map(file => loadOverlayPatches('Schedule Web every-step overlay', file)), + ] + const row = composeEntries(layers).find(entry => entry.id === 'preset-standard') + if (row === undefined) throw new Error('the shipped Web surface declares no preset-standard row') + const config = row.config as { plugins: Array<{ id?: string; config?: unknown; disabled?: boolean }> } + // A preset plugin cannot be addressed from a top-level patch, so the overlay + // restates the shipped `preset-standard` row with the two reminder rows the + // stopgap disables turned back on, keeping the scenario on the shipped + // composition. + const plugins = config.plugins.map(plugin => plugin.id === 'preset-time-context' + ? { ...plugin, disabled: false, config: { refreshIntervalMs: 0 } } + : plugin.id === 'tool-schedule' + ? { ...plugin, disabled: false } + : plugin) + const path = join(dir, 'time-context-every-step.patch.yml') + await writeFile(path, dump([ + { id: 'time-context', disabled: false, config: { refreshIntervalMs: 0 } }, + { id: 'schedule', disabled: false }, + { id: 'ui-schedule', disabled: false }, + { id: 'preset-standard', config: { ...config, plugins } }, + ], { schema: entryListSchema, noRefs: true, lineWidth: -1 })) + return path +} const CATALOG_NOW = Date.parse('2099-08-25T12:00:00.000Z') const CATALOG_SESSION_ID = SessionId('schedule-catalog-web-e2e') const CATALOG_TITLE = 'Active schedule catalog' @@ -266,13 +308,15 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => { let everyAssistantReply: SessionEvent<'assistant/message'> | undefined let everyRecords: readonly [EveryScheduleRecord, EveryScheduleRecord] let tripwire: ReturnType + let overlayRoot: string const afterAdapter = new ReminderAdapter() const atAdapter = new BrowserZoneAtAdapter() const everyAdapter = new EveryReminderAdapter() beforeAll(async () => { + overlayRoot = await mkdtemp(join(tmpdir(), 'dsh-schedule-every-step-')) scaffold = await launchWebScaffold({ - extraOverlayPath: fileURLToPath(new URL('./fixtures/time-context-every-step.patch.yml', import.meta.url)), + extraOverlayPath: await writeReminderOverlay(overlayRoot), }) scaffold.ctx.effect( () => scaffold.ctx.llm.registerAdapter([AFTER_PROVIDER], afterAdapter), @@ -309,6 +353,9 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => { sessionId: SessionId('schedule-after-web-e2e'), meta: { cwd }, agentOptions: { provider: AFTER_PROVIDER, model: MODEL }, + // The reminder tools are preset-level Consumers, so a directly created Agent + // needs the default preset the product mounts. + setup: agentCtx => scaffold.ctx.agentPresets.mount(agentCtx).then(() => undefined), }) afterHandle.agent.session.append('session/title', { title: 'Scheduled After follow-up', @@ -346,6 +393,9 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => { sessionId: SessionId('schedule-every-web-e2e'), meta: { cwd }, agentOptions: { provider: EVERY_PROVIDER, model: MODEL }, + // The reminder tools are preset-level Consumers, so a directly created Agent + // needs the default preset the product mounts. + setup: agentCtx => scaffold.ctx.agentPresets.mount(agentCtx).then(() => undefined), }) everyHandle.agent.session.append('session/title', { title: 'Fixed-rate reminder batch', @@ -395,6 +445,9 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => { sessionId: SessionId('schedule-at-web-e2e'), meta: { cwd }, agentOptions: { provider: AT_PROVIDER, model: MODEL }, + // The reminder tools are preset-level Consumers, so a directly created Agent + // needs the default preset the product mounts. + setup: agentCtx => scaffold.ctx.agentPresets.mount(agentCtx).then(() => undefined), }) atHandle.agent.session.append('session/title', { title: 'Explicit local-time reminder', @@ -442,6 +495,7 @@ describe.skipIf(MODE === 'record')('web e2e: conversational reminders', () => { await everyHandle?.dispose().catch((error: unknown) => failures.push(error)) await afterHandle?.dispose().catch((error: unknown) => failures.push(error)) await scaffold?.close().catch((error: unknown) => failures.push(error)) + await rm(overlayRoot, { recursive: true, force: true }).catch((error: unknown) => failures.push(error)) if (failures.length === 1) throw failures[0] if (failures.length > 1) throw new AggregateError(failures, 'Schedule Web evidence teardown failed') }) @@ -706,11 +760,13 @@ describe.skipIf(MODE === 'record')('web e2e: active Schedule catalog', () => { let browser: Browser let page: Page let tripwire: ReturnType + let overlayRoot: string beforeAll(async () => { const fixture = await readFile(CATALOG_FIXTURE, 'utf8') + overlayRoot = await mkdtemp(join(tmpdir(), 'dsh-schedule-catalog-web-')) scaffold = await launchWebScaffold({ - extraOverlayPath: fileURLToPath(new URL('./fixtures/time-context-every-step.patch.yml', import.meta.url)), + extraOverlayPath: await writeReminderOverlay(overlayRoot), }) await seedSession(scaffold, fixture, CATALOG_SESSION_ID, 'standard') const records = foldScheduleEvents(fixture.trim().split('\n').slice(1).map(line => JSON.parse(line) as SessionEvent)).active @@ -751,6 +807,7 @@ describe.skipIf(MODE === 'record')('web e2e: active Schedule catalog', () => { const failures: unknown[] = [] await browser?.close().catch((error: unknown) => failures.push(error)) await scaffold?.close().catch((error: unknown) => failures.push(error)) + await rm(overlayRoot, { recursive: true, force: true }).catch((error: unknown) => failures.push(error)) if (failures.length === 1) throw failures[0] if (failures.length > 1) throw new AggregateError(failures, 'Schedule catalog teardown failed') }) @@ -850,6 +907,26 @@ describe.skipIf(MODE === 'record')('web e2e: active Schedule catalog', () => { ]) { expect(shipped.filter(entry => entry.id === row.id && entry.name === row.name)).toHaveLength(1) } + // Each preset that offers reminders declares the clock and the tool package, + // disabled with the Host rows while the stopgap is in place; `minimal` + // declares neither. + const presetPlugins = (id: string): Array<{ id?: string; name?: string; disabled?: boolean }> => { + const row = shipped.find(entry => entry.id === id) + if (row === undefined) throw new Error(`missing shipped preset row ${id}`) + return (row.config as { plugins: Array<{ id?: string; name?: string; disabled?: boolean }> }).plugins + } + for (const id of ['preset-standard', 'preset-ptc', 'preset-cordis']) { + const plugins = presetPlugins(id) + expect(plugins.filter(row => row.id === 'preset-time-context' + && row.name === '@deepseek-ai/dsh-time-context')).toHaveLength(1) + expect(plugins.filter(row => row.id === 'tool-schedule' + && row.name === '@deepseek-ai/dsh-tool-schedule')).toHaveLength(1) + for (const name of ['@deepseek-ai/dsh-time-context', '@deepseek-ai/dsh-tool-schedule']) { + expect(plugins.filter(row => row.name === name && row.disabled === true)).toHaveLength(1) + } + } + expect(presetPlugins('preset-minimal').some(row => row.name === '@deepseek-ai/dsh-time-context' + || row.name === '@deepseek-ai/dsh-tool-schedule')).toBe(false) await page.getByRole('button', { name: 'Automation tasks', exact: true }).click() const manager = page.getByTestId('task-manager-page')