@yuriai/web 0.2.27-beta.8 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-BJ42lGZD.js → AgentAvatar-BybF1ayP.js} +1 -1
- package/dist/assets/AssistantContactStatus-BwpxTn0d.js +3 -0
- package/dist/assets/{AssistantUnreadBadge-QwhBfXpC.js → AssistantUnreadBadge-DqThZdCe.js} +1 -1
- package/dist/assets/{AssistantView-D7ryIKL0.js → AssistantView-DPUDCXoY.js} +1 -1
- package/dist/assets/{DiagramView-ERrGEBDp.js → DiagramView-CHVLoYrV.js} +1 -1
- package/dist/assets/{FadeInOnReveal-Bu2GvaM9.js → FadeInOnReveal-Cj3JXYvE.js} +1 -1
- package/dist/assets/{GuiPluginSurface-MzQgEZNr.js → GuiPluginSurface-CBZYeKHb.js} +1 -1
- package/dist/assets/{GuiPluginWindow-DZMmlQzx.js → GuiPluginWindow-_Z5wycnH.js} +1 -1
- package/dist/assets/{Icon-Dj4CCqCP.js → Icon-CeRMtJa8.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-BnFXgUuO.js → ImageLoadingPlaceholder-DjLaKB4o.js} +1 -1
- package/dist/assets/{LoadingImage-PBnivDKv.js → LoadingImage-DG3otL5V.js} +1 -1
- package/dist/assets/MarkdownRenderer-C8rv6z7p.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-CfyXL4rg.js → MarkdownRendererImpl-_plqOlsV.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-BGadklK1.js → MarkstreamRendererImpl-bs8HZ4Ra.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-DqajQdB4.js → MobileDetailNavigation-SeT764Ps.js} +1 -1
- package/dist/assets/{MobileResizableSheet-BvdUgwA3.js → MobileResizableSheet-BY1-oo_E.js} +1 -1
- package/dist/assets/{MobileShareBridge-3oPoYnry.js → MobileShareBridge-Dw8gLtJD.js} +2 -2
- package/dist/assets/MobileTabPageHeader-EsrOCLyg.js +2 -0
- package/dist/assets/{MultiRunWindow-yhs0Ih5_.js → MultiRunWindow-C-Qw_g7N.js} +1 -1
- package/dist/assets/{OnboardingScreen-Bi1VWFQC.js → OnboardingScreen-CGqabMbp.js} +1 -1
- package/dist/assets/{OverlayScrollbar-BBDwGvGO.js → OverlayScrollbar-AGSWQKg-.js} +1 -1
- package/dist/assets/{SettingsView-BSf-SJUA.js → SettingsView-BLfFnnnX.js} +14 -14
- package/dist/assets/{SettingsWindow-BvSXVMTm.js → SettingsWindow-lyYO8Byy.js} +1 -1
- package/dist/assets/{TerminalView-DhL01N7e.js → TerminalView-OHqpkHzz.js} +1 -1
- package/dist/assets/{ToolOutputDialog-C8lnH4Ky.js → ToolOutputDialog-DU4Pb1s0.js} +1 -1
- package/dist/assets/{YuriLogo-D8asj1CS.js → YuriLogo-Bb6yHagP.js} +1 -1
- package/dist/assets/{appThemeRegistry-C-maYSdv.js → appThemeRegistry-9j-rCSlE.js} +1 -1
- package/dist/assets/{button-vXOdzd8x.js → button-Bjh2BSXh.js} +1 -1
- package/dist/assets/{capgoAdapter-DJ_h2x5D.js → capgoAdapter-DERfot6h.js} +1 -1
- package/dist/assets/{collapsible-DwDQs3Wa.js → collapsible-BEAHoxNi.js} +1 -1
- package/dist/assets/{context-menu-BabBujQ-.js → context-menu-BxLcot-3.js} +1 -1
- package/dist/assets/device-BcRP6Tjd.js +2 -0
- package/dist/assets/{diagram-HwgrQxY5.js → diagram-CXVm2vzI.js} +1 -1
- package/dist/assets/{dialog-Dnf626tb.js → dialog-nshKUSE5.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-CBc_a-Nv.js → dropdown-menu.styles-M78xpvb2.js} +1 -1
- package/dist/assets/{es-BQkO-Odr.js → es-N9ZkQwG9.js} +2 -2
- package/dist/assets/fileMentionAutocompleteState-BZJqfgae.js +2 -0
- package/dist/assets/{fileMentionTouchSelection-CKPnEetl.js → fileMentionTouchSelection-B9NbPN9D.js} +2 -2
- package/dist/assets/{fileReferenceActions-g7KZLi_G.js → fileReferenceActions-CrIAce3K.js} +1 -1
- package/dist/assets/{fr-C852roK5.js → fr-CIGqV46N.js} +2 -2
- package/dist/assets/{gitApi-CVq5oKCd.js → gitApi-CY3D5CF0.js} +1 -1
- package/dist/assets/{gitApiHttp-BYOIbYIh.js → gitApiHttp-B7vYwgBh.js} +4 -4
- package/dist/assets/{gui-M_Rbwkyu.js → gui-CJjEj3l4.js} +1 -1
- package/dist/assets/host-CnVx34Dh.js +1 -0
- package/dist/assets/{image-loading-D5UhMj7Z.js → image-loading-D6kOgU4w.js} +1 -1
- package/dist/assets/{input-BtM712b1.js → input-3Re4pmHm.js} +1 -1
- package/dist/assets/insertionBoundaries-DK7XYF8d.js +1 -0
- package/dist/assets/{ja-BqC39qK6.js → ja-DAhnTq6V.js} +2 -2
- package/dist/assets/{ko-BMaChAWh.js → ko-FbMgNKcI.js} +2 -2
- package/dist/assets/main-B_THXYMs.js +2 -0
- package/dist/assets/main-CpcudEZb.js +169 -0
- package/dist/assets/{markdownHeightCache-Bf8iisO4.js → markdownHeightCache-DVWGXtAX.js} +1 -1
- package/dist/assets/{mcpQueries-DpXqegX5.js → mcpQueries-CdOYmUdO.js} +1 -1
- package/dist/assets/miniChat-DxZiTnAZ.js +2 -0
- package/dist/assets/mobile-BJuATiaC.js +2 -0
- package/dist/assets/{mobileBackNavigation-DZcI7aZg.js → mobileBackNavigation-CgZndzFA.js} +1 -1
- package/dist/assets/{multirun-hzspPepd.js → multirun-BlaYsQi2.js} +1 -1
- package/dist/assets/{native-H7K64Ulc.js → native-BYMhr-xH.js} +1 -1
- package/dist/assets/{native-config-CddZtLQ1.js → native-config-BpsFKLGl.js} +1 -1
- package/dist/assets/{persistence-BT8045Ue.js → persistence-CWuLIq1J.js} +2 -2
- package/dist/assets/{pl-Ubs8p28T.js → pl-DzX0cbiQ.js} +2 -2
- package/dist/assets/{projectMeta-CEf0QPmD.js → projectMeta-CnXHTolN.js} +1 -1
- package/dist/assets/{pt-BR-8rAOjJrs.js → pt-BR-C5yvwyDK.js} +2 -2
- package/dist/assets/queue-abort-optimistic-DCLBpirg.js +1 -0
- package/dist/assets/{readiness-Dyr7314z.js → readiness-U16Qor79.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-n-nhgy1V.js +2 -0
- package/dist/assets/renderMobileApp-DBj_7RlD.js +28 -0
- package/dist/assets/{runtimeConfig-B8VHHNxj.js → runtimeConfig-BBgkLVr_.js} +1 -1
- package/dist/assets/runtimeEndpointReset-BvSQVFfx.js +149 -0
- package/dist/assets/{scheduledTaskNavigation-Zm87Nydi.js → scheduledTaskNavigation-EomDNVu2.js} +1 -1
- package/dist/assets/sessionLookup-C_CCp7MJ.js +1 -0
- package/dist/assets/{sortable-tabs-strip-D4pVoodN.js → sortable-tabs-strip-p16Pn6Zz.js} +1 -1
- package/dist/assets/{speechSettingsQueries-RlCLMBtr.js → speechSettingsQueries-CBSEAKyj.js} +2 -2
- package/dist/assets/src-u-YDfCVw.css +2 -0
- package/dist/assets/{store-ME7oHni1.js → store-DVfZQktm.js} +4 -3
- package/dist/assets/{terminalApi-BSaclMDJ.js → terminalApi-rl9mZAlB.js} +1 -1
- package/dist/assets/{textarea-B98rsLs7.js → textarea-C6VQ7dHH.js} +1 -1
- package/dist/assets/{tooltip-B9810jbK.js → tooltip-Dnc6GA-X.js} +1 -1
- package/dist/assets/types-DnZw0gLD.js +2 -0
- package/dist/assets/{uk-LzwzUApL.js → uk-zbDcUpBy.js} +2 -2
- package/dist/assets/{useAppFontEffects-D2C1sBYM.js → useAppFontEffects-CEgDiZHu.js} +49 -49
- package/dist/assets/{useAssistantUIStore-TUN_ycy5.js → useAssistantUIStore-CfaQV3ID.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-B2o4IFmd.js +1 -0
- package/dist/assets/useEffectiveDirectory-BOYMJ6k7.js +1 -0
- package/dist/assets/{useFontPreferences-BlhlCJCX.js → useFontPreferences-DeqW9nRx.js} +1 -1
- package/dist/assets/useMobileNavigationStore-DlvrZQ49.js +17 -0
- package/dist/assets/{useUIStore-DRx6OgCp.js → useUIStore-C6CE42oh.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-D093jNsH.js → useWorkerHighlightedLines-EcJThS4x.js} +1 -1
- package/dist/assets/{vendor-effect-DV9F8PTZ.js → vendor-effect-X1Hqc7ba.js} +13 -13
- package/dist/assets/vendor-opencode-client-cQ47ywrT.js +23 -0
- package/dist/assets/{vendor-opencode-plugin-BBOP6WNx.js → vendor-opencode-plugin-BmdTE4Te.js} +1 -1
- package/dist/assets/vendor-opencode-schema-DWT45VBX.js +1 -0
- package/dist/assets/vendor-solid-js-D98iXT7C.js +1 -0
- package/dist/assets/vendor-zod-DZzbCm1s.js +55 -0
- package/dist/assets/{zh-CN-D-FVCeks.js → zh-CN-BHRJ7CF3.js} +2 -2
- package/dist/assets/{zh-TW-B9iH_NXL.js → zh-TW-BFI_YFd-.js} +2 -2
- package/dist/index.html +12 -12
- package/dist/mini-chat.html +12 -12
- package/dist/mobile.html +12 -12
- package/package.json +1 -1
- package/server/index.js +2 -145
- package/server/lib/assistants/DOCUMENTATION.md +63 -10
- package/server/lib/assistants/cards.js +1 -1
- package/server/lib/assistants/channel-image.js +92 -0
- package/server/lib/assistants/channel-image.test.js +76 -0
- package/server/lib/assistants/channel-output-store.test.js +41 -0
- package/server/lib/assistants/channel-output.integration.test.js +128 -0
- package/server/lib/assistants/channel-output.js +90 -0
- package/server/lib/assistants/channel-output.test.js +79 -0
- package/server/lib/assistants/channels/DOCUMENTATION.md +52 -14
- package/server/lib/assistants/channels/PROTOCOLS.md +23 -1
- package/server/lib/assistants/channels/dingtalk-chat-adapter.js +19 -7
- package/server/lib/assistants/channels/dingtalk-chat-adapter.test.js +8 -0
- package/server/lib/assistants/channels/routes.js +12 -0
- package/server/lib/assistants/channels/routes.test.js +34 -0
- package/server/lib/assistants/channels/runtime.js +117 -26
- package/server/lib/assistants/channels/runtime.test.js +179 -5
- package/server/lib/assistants/channels/sdk-adapters.js +15 -3
- package/server/lib/assistants/channels/sdk-adapters.test.js +17 -0
- package/server/lib/assistants/channels/store.js +9 -6
- package/server/lib/assistants/channels/store.test.js +21 -11
- package/server/lib/assistants/channels/transport.js +2 -1
- package/server/lib/assistants/channels/wecom-chat-adapter.js +16 -2
- package/server/lib/assistants/channels/wecom-chat-adapter.test.js +21 -0
- package/server/lib/assistants/contact-store.js +9 -3
- package/server/lib/assistants/contact-store.test.js +27 -0
- package/server/lib/assistants/contact-tools.js +65 -75
- package/server/lib/assistants/contact-tools.test.js +114 -22
- package/server/lib/assistants/harness.js +80 -34
- package/server/lib/assistants/harness.test.js +68 -20
- package/server/lib/assistants/resource-reference.integration.test.js +284 -0
- package/server/lib/assistants/routes.js +0 -3
- package/server/lib/assistants/service.js +116 -69
- package/server/lib/assistants/service.test.js +31 -17
- package/server/lib/assistants/weixin/DOCUMENTATION.md +34 -9
- package/server/lib/assistants/weixin/api.js +43 -1
- package/server/lib/assistants/weixin/api.test.js +28 -0
- package/server/lib/assistants/weixin/chat-adapter.js +8 -2
- package/server/lib/assistants/weixin/inbound.js +5 -3
- package/server/lib/assistants/weixin/inbound.test.js +20 -0
- package/server/lib/assistants/weixin/runtime.js +27 -18
- package/server/lib/assistants/weixin/runtime.test.js +36 -0
- package/server/lib/assistants/weixin/store.js +8 -4
- package/server/lib/assistants/weixin/store.test.js +21 -0
- package/server/lib/assistants/yuri-project.http.test.js +9 -3
- package/server/lib/notifications/DOCUMENTATION.md +6 -0
- package/server/lib/notifications/runtime.js +26 -15
- package/server/lib/notifications/runtime.test.js +14 -13
- package/server/lib/opencode/DOCUMENTATION.md +9 -0
- package/server/lib/opencode/auth.d.ts +6 -2
- package/server/lib/opencode/core-routes.js +0 -1
- package/server/lib/opencode/feature-routes-runtime.js +0 -24
- package/server/lib/opencode/location-release.d.ts +5 -1
- package/server/lib/opencode/managed-capabilities/scheduled-task.js +1 -1
- package/server/lib/opencode/managed-capabilities-runtime.test.js +1 -1
- package/server/lib/opencode/native-goal.js +15 -0
- package/server/lib/opencode/native-goal.test.js +17 -0
- package/server/lib/opencode/settings-helpers.js +0 -6
- package/server/lib/opencode/shutdown-runtime.js +0 -2
- package/server/lib/projects/project-config.js +3 -6
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +10 -35
- package/server/lib/scheduled-tasks/managed-tool-route.js +1 -30
- package/server/lib/scheduled-tasks/routes.js +0 -26
- package/server/lib/scheduled-tasks/runtime.js +33 -257
- package/server/lib/scheduled-tasks/runtime.test.js +24 -65
- package/server/lib/session-metadata/DOCUMENTATION.md +9 -12
- package/server/lib/session-metadata/routes.js +4 -38
- package/server/lib/session-metadata/routes.test.js +2 -2
- package/dist/assets/AssistantContactStatus-dtkObamV.js +0 -3
- package/dist/assets/MarkdownRenderer-BajF4gUU.js +0 -2
- package/dist/assets/MobileTabPageHeader-B6cRyIRH.js +0 -2
- package/dist/assets/device-BjRYYXNT.js +0 -2
- package/dist/assets/host-BW3FEJdU.js +0 -1
- package/dist/assets/insertionBoundaries-Dx3WAY6i.js +0 -1
- package/dist/assets/main-9uP2z1qT.js +0 -2
- package/dist/assets/main-Mey7bCWf.js +0 -169
- package/dist/assets/miniChat-DqZvVkme.js +0 -2
- package/dist/assets/mobile-DXAWjYcN.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-DoOq8Cuo.js +0 -2
- package/dist/assets/renderMobileApp-TTxtOb8b.js +0 -28
- package/dist/assets/runtimeEndpointReset-BC6XWntz.js +0 -149
- package/dist/assets/sessionLookup-De53jDwM.js +0 -1
- package/dist/assets/src-lE4uqaHS.css +0 -2
- package/dist/assets/types-DFf9vd1b.js +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-BjKaHN0x.js +0 -1
- package/dist/assets/useEffectiveDirectory-TEvyiQSC.js +0 -1
- package/dist/assets/useMobileNavigationStore-DTvJV9s-.js +0 -23
- package/dist/assets/vendor-opencode-client-ZeOZ4Efz.js +0 -23
- package/dist/assets/vendor-solid-js-9wmPZH9g.js +0 -1
- package/dist/assets/vendor-zod-Dzk5kdUU.js +0 -39
- package/server/lib/session-goal/DOCUMENTATION.md +0 -371
- package/server/lib/session-goal/capability.js +0 -57
- package/server/lib/session-goal/capability.test.js +0 -33
- package/server/lib/session-goal/objectives.js +0 -61
- package/server/lib/session-goal/routes.js +0 -274
- package/server/lib/session-goal/routes.test.js +0 -211
- package/server/lib/session-goal/runtime.js +0 -2452
- package/server/lib/session-goal/runtime.test.js +0 -2125
|
@@ -1,2125 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { createSessionMetadataStore } from '../session-metadata/session-metadata-store.js';
|
|
3
|
-
import {
|
|
4
|
-
configureServerOpenCodeFetchGate,
|
|
5
|
-
} from '../opencode/server-opencode-fetch.js';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import os from 'node:os';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import { pathToFileURL } from 'node:url';
|
|
10
|
-
import {
|
|
11
|
-
accountGoalTokenSpend,
|
|
12
|
-
buildContinuationMessageID,
|
|
13
|
-
buildPendingContinuation,
|
|
14
|
-
createSessionGoalRuntime,
|
|
15
|
-
extractExecutionModel,
|
|
16
|
-
messageTokenSpend,
|
|
17
|
-
parsePendingContinuation,
|
|
18
|
-
projectGoalMessages,
|
|
19
|
-
readGoalExecutionGeneration,
|
|
20
|
-
shouldAdvanceGoalExecutionGeneration,
|
|
21
|
-
unwrapSessionMessages,
|
|
22
|
-
withGoalExecutionGeneration,
|
|
23
|
-
} from './runtime.js';
|
|
24
|
-
|
|
25
|
-
// Host SDK writes share the runtime-contract gate. Unit tests have no lifecycle
|
|
26
|
-
// contract — allow missing so real switchAgent/switchModel/prompt reach fetch fixtures.
|
|
27
|
-
beforeAll(() => {
|
|
28
|
-
configureServerOpenCodeFetchGate(null, { allowMissingContract: true });
|
|
29
|
-
});
|
|
30
|
-
afterAll(() => {
|
|
31
|
-
configureServerOpenCodeFetchGate(null);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
/** Resolve installed @opencode/schema SessionMessage next to @opencode/client (no extra dep). */
|
|
35
|
-
const loadInstalledSessionMessageSchema = async () => {
|
|
36
|
-
const candidates = [];
|
|
37
|
-
const tryClientLink = (clientLink) => {
|
|
38
|
-
try {
|
|
39
|
-
if (!fs.existsSync(clientLink)) return;
|
|
40
|
-
const clientDir = fs.realpathSync(clientLink);
|
|
41
|
-
candidates.push(path.join(path.dirname(clientDir), 'schema', 'dist', 'session-message.js'));
|
|
42
|
-
} catch {
|
|
43
|
-
// ignore missing link
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
// packages/web dependency
|
|
47
|
-
tryClientLink(path.join(process.cwd(), 'node_modules/@opencode/client'));
|
|
48
|
-
tryClientLink(path.join(process.cwd(), 'packages/web/node_modules/@opencode/client'));
|
|
49
|
-
// bun nested install layout
|
|
50
|
-
const bunRoot = path.join(process.cwd(), 'node_modules/.bun');
|
|
51
|
-
if (fs.existsSync(bunRoot)) {
|
|
52
|
-
for (const name of fs.readdirSync(bunRoot)) {
|
|
53
|
-
if (!name.startsWith('@opencode+client@')) continue;
|
|
54
|
-
candidates.push(path.join(
|
|
55
|
-
bunRoot,
|
|
56
|
-
name,
|
|
57
|
-
'node_modules/@opencode/schema/dist/session-message.js',
|
|
58
|
-
));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
for (const schemaPath of candidates) {
|
|
62
|
-
if (fs.existsSync(schemaPath)) {
|
|
63
|
-
return import(pathToFileURL(schemaPath).href);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
throw new Error('installed @opencode/schema session-message not found beside @opencode/client');
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// A session whose last assistant message is an orphaned incomplete turn: the
|
|
70
|
-
// app was force-killed mid-generation, so opencode left a message with no
|
|
71
|
-
// time.completed AND no error, while the session is actually idle. Before the
|
|
72
|
-
// quiescence fix this was misclassified as "busy" and the tick bailed forever,
|
|
73
|
-
// stranding a restarted active goal on "evaluating".
|
|
74
|
-
const orphanIncompleteAssistant = {
|
|
75
|
-
info: { id: 'msg-orphan', role: 'assistant', time: { created: 100 }, providerID: 'p', modelID: 'm' },
|
|
76
|
-
parts: [],
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const buildSession = (status = 'active') => ({
|
|
80
|
-
id: 'ses-goal',
|
|
81
|
-
directory: '/repo',
|
|
82
|
-
metadata: {
|
|
83
|
-
yuri: {
|
|
84
|
-
goal: {
|
|
85
|
-
id: 'goal-1',
|
|
86
|
-
status,
|
|
87
|
-
objective: 'finish the feature',
|
|
88
|
-
objectiveFile: false,
|
|
89
|
-
statusReason: status === 'active' ? 'resumed' : '',
|
|
90
|
-
turnsUsed: 0,
|
|
91
|
-
tokensUsed: 0,
|
|
92
|
-
tokensBaseline: 0,
|
|
93
|
-
tokensCommitted: 0,
|
|
94
|
-
lastAccountedMessageID: '',
|
|
95
|
-
blockedStreak: 0,
|
|
96
|
-
auditFailStreak: 0,
|
|
97
|
-
createdAt: 0,
|
|
98
|
-
updatedAt: Date.now(),
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
/** Match both legacy `/session/...` and official v2 `/api/session/...` paths. */
|
|
105
|
-
const pathEndsWith = (urlPath, suffix) => {
|
|
106
|
-
const normalized = String(urlPath || '').split('?')[0];
|
|
107
|
-
return normalized.endsWith(suffix) || normalized.endsWith(`/api${suffix}`);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const jsonResponse = (body, status = 200) => new Response(
|
|
111
|
-
body === null || body === undefined ? null : JSON.stringify(body),
|
|
112
|
-
{ status, headers: { 'Content-Type': 'application/json' } },
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const emptyResponse = (status = 204) => new Response(null, { status });
|
|
116
|
-
|
|
117
|
-
// Build a mock fetch that answers the endpoints the goal tick needs. `messages`
|
|
118
|
-
// is the message list returned for the session; `liveStatus` is the type
|
|
119
|
-
// returned by /session/status (or mapped from /session/active) for the session.
|
|
120
|
-
const makeFetch = ({ messages, liveStatus }) => {
|
|
121
|
-
const calls = { promptAsync: 0, prompt: 0, patchSession: 0 };
|
|
122
|
-
const session = buildSession();
|
|
123
|
-
return {
|
|
124
|
-
calls,
|
|
125
|
-
fetch: async (input, init = {}) => {
|
|
126
|
-
const url = String(input);
|
|
127
|
-
const reqPath = url.split('?')[0];
|
|
128
|
-
if (pathEndsWith(reqPath, '/session/status')) {
|
|
129
|
-
return jsonResponse({ 'ses-goal': { type: liveStatus } });
|
|
130
|
-
}
|
|
131
|
-
if (pathEndsWith(reqPath, '/session/active')) {
|
|
132
|
-
const data = liveStatus === 'busy' || liveStatus === 'retry'
|
|
133
|
-
? { 'ses-goal': true }
|
|
134
|
-
: {};
|
|
135
|
-
return jsonResponse({ data });
|
|
136
|
-
}
|
|
137
|
-
if (pathEndsWith(reqPath, '/session/ses-goal/message')) {
|
|
138
|
-
// Official v2 SessionMessagesResponse shape.
|
|
139
|
-
return jsonResponse({ data: new URL(url).searchParams.get('order') === 'desc' ? [...messages].reverse() : messages, cursor: {} });
|
|
140
|
-
}
|
|
141
|
-
if (pathEndsWith(reqPath, '/session/ses-goal') && !reqPath.includes('/message')) {
|
|
142
|
-
if (init.method === 'PATCH') {
|
|
143
|
-
calls.patchSession += 1;
|
|
144
|
-
// openCodeFetch (no /api) expects bare session; SDK wraps { data }.
|
|
145
|
-
return jsonResponse(reqPath.includes('/api/') ? { data: session } : session);
|
|
146
|
-
}
|
|
147
|
-
return jsonResponse(reqPath.includes('/api/') ? { data: session } : session);
|
|
148
|
-
}
|
|
149
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
150
|
-
if (pathEndsWith(reqPath, '/prompt_async')) calls.promptAsync += 1;
|
|
151
|
-
else calls.prompt += 1;
|
|
152
|
-
// v2 session.prompt successStatus 200 with SessionInboxUser body.
|
|
153
|
-
return jsonResponse({
|
|
154
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
if (pathEndsWith(reqPath, '/model') || pathEndsWith(reqPath, '/agent')) {
|
|
158
|
-
return emptyResponse(204);
|
|
159
|
-
}
|
|
160
|
-
return jsonResponse(reqPath.includes('/api/') ? { data: session } : session);
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const makeRuntime = () =>
|
|
166
|
-
createSessionGoalRuntime({
|
|
167
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
168
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
169
|
-
getSmallModelService: async () => ({
|
|
170
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"in progress"}' }),
|
|
171
|
-
}),
|
|
172
|
-
idleQuietMs: 1_000_000, // avoid incidental re-arms in the test
|
|
173
|
-
kickoffQuietMs: 1,
|
|
174
|
-
maxAutoTurns: 20,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Override the module-level fetch used by openCodeFetch via globalThis.
|
|
178
|
-
const withFetch = async (fetchImpl, fn) => {
|
|
179
|
-
const original = globalThis.fetch;
|
|
180
|
-
globalThis.fetch = fetchImpl;
|
|
181
|
-
try {
|
|
182
|
-
await fn();
|
|
183
|
-
} finally {
|
|
184
|
-
globalThis.fetch = original;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
describe('session-goal pending continuation helpers', () => {
|
|
189
|
-
it('parses and builds durable pendingContinuation admission records', () => {
|
|
190
|
-
expect(parsePendingContinuation(null)).toBeNull();
|
|
191
|
-
expect(parsePendingContinuation({ messageID: 'msg_x' })).toBeNull();
|
|
192
|
-
const built = buildPendingContinuation({
|
|
193
|
-
messageID: 'msg_goalc_g_0_1',
|
|
194
|
-
goalId: 'g',
|
|
195
|
-
generation: 0,
|
|
196
|
-
turnsUsed: 1,
|
|
197
|
-
phase: 'reserved',
|
|
198
|
-
text: 'Continue…',
|
|
199
|
-
providerID: 'p',
|
|
200
|
-
modelID: 'm',
|
|
201
|
-
agent: 'build',
|
|
202
|
-
});
|
|
203
|
-
expect(parsePendingContinuation(built)).toMatchObject({
|
|
204
|
-
messageID: 'msg_goalc_g_0_1',
|
|
205
|
-
phase: 'reserved',
|
|
206
|
-
turnsUsed: 1,
|
|
207
|
-
providerID: 'p',
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('session-goal v2 message projection helpers', () => {
|
|
213
|
-
it('unwraps SessionMessagesResponse, bare arrays, and projects raw SessionMessageInfo', () => {
|
|
214
|
-
expect(unwrapSessionMessages(null)).toBeNull();
|
|
215
|
-
expect(unwrapSessionMessages({ data: [{ id: 'a', type: 'user', text: 'hi', time: { created: 1 } }], cursor: {} }))
|
|
216
|
-
.toEqual([{ id: 'a', type: 'user', text: 'hi', time: { created: 1 } }]);
|
|
217
|
-
const projected = projectGoalMessages({
|
|
218
|
-
data: [
|
|
219
|
-
{ id: 'u1', type: 'user', text: 'go', time: { created: 1 } },
|
|
220
|
-
{
|
|
221
|
-
id: 'a1',
|
|
222
|
-
type: 'assistant',
|
|
223
|
-
agent: 'build',
|
|
224
|
-
model: { id: 'm', providerID: 'p', variant: 'fast' },
|
|
225
|
-
time: { created: 2, completed: 3 },
|
|
226
|
-
content: [{ type: 'text', text: 'done' }],
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
id: 'c1',
|
|
230
|
-
type: 'compaction',
|
|
231
|
-
status: 'completed',
|
|
232
|
-
reason: 'auto',
|
|
233
|
-
summary: 'summary text',
|
|
234
|
-
recent: '',
|
|
235
|
-
time: { created: 4 },
|
|
236
|
-
},
|
|
237
|
-
],
|
|
238
|
-
cursor: {},
|
|
239
|
-
}, 'ses-1');
|
|
240
|
-
expect(projected).toHaveLength(3);
|
|
241
|
-
expect(projected[0].info.role).toBe('user');
|
|
242
|
-
expect(projected[1].info.role).toBe('assistant');
|
|
243
|
-
expect(projected[1].parts[0].text).toBe('done');
|
|
244
|
-
expect(projected[2].info.summary).toBe(true);
|
|
245
|
-
expect(extractExecutionModel(projected[1].info)).toEqual({
|
|
246
|
-
providerID: 'p',
|
|
247
|
-
modelID: 'm',
|
|
248
|
-
variant: 'fast',
|
|
249
|
-
agent: 'build',
|
|
250
|
-
});
|
|
251
|
-
expect(buildContinuationMessageID({ goalId: 'goal-1', generation: 2, turnsUsed: 5 }))
|
|
252
|
-
.toBe('msg_goalc_goal-1_2_5');
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('continuation id satisfies installed SessionMessage.ID (msg_ prefix)', async () => {
|
|
256
|
-
const SessionMessage = await loadInstalledSessionMessageSchema();
|
|
257
|
-
const legal = buildContinuationMessageID({ goalId: 'goal-1', generation: 2, turnsUsed: 5 });
|
|
258
|
-
expect(legal.startsWith('msg_')).toBe(true);
|
|
259
|
-
expect(SessionMessage.ID.make(legal)).toBe(legal);
|
|
260
|
-
// Legacy goalc_ prefix is rejected by the official schema contract.
|
|
261
|
-
expect(() => SessionMessage.ID.make('goalc_goal-1_2_5')).toThrow();
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
describe('session-goal continuation delivery', () => {
|
|
266
|
-
it.each([false, true])('continues after a completed compaction beyond the first message page (HTTP fallback: %s)', async (fallback) => {
|
|
267
|
-
const messages = Array.from({ length: 42 }, (_, index) => ({
|
|
268
|
-
id: `msg_${String(index).padStart(3, '0')}`,
|
|
269
|
-
type: index === 41 ? 'compaction' : index % 2 ? 'user' : 'assistant',
|
|
270
|
-
time: index === 41 ? { created: index + 1 } : { created: index + 1, completed: index + 2 },
|
|
271
|
-
model: { providerID: 'p', id: 'm' },
|
|
272
|
-
agent: 'build',
|
|
273
|
-
...(index === 41 ? { status: 'completed', summary: 'Work remains' } : { text: 'Working' }),
|
|
274
|
-
}));
|
|
275
|
-
const fixture = makeFetch({ messages, liveStatus: 'idle' });
|
|
276
|
-
const runtime = makeRuntime();
|
|
277
|
-
try {
|
|
278
|
-
await withFetch(async (input, init) => {
|
|
279
|
-
const url = new URL(String(input));
|
|
280
|
-
if (pathEndsWith(url.pathname, '/session/ses-goal/message')) {
|
|
281
|
-
if (fallback && url.pathname.startsWith('/api/')) return jsonResponse({ error: 'unavailable' }, 503);
|
|
282
|
-
const ordered = url.searchParams.get('order') === 'desc' ? [...messages].reverse() : messages;
|
|
283
|
-
return jsonResponse({ data: ordered.slice(0, Number(url.searchParams.get('limit') || 40)), cursor: {} });
|
|
284
|
-
}
|
|
285
|
-
return fixture.fetch(input, init);
|
|
286
|
-
}, async () => runtime.runTick('ses-goal', '/repo'));
|
|
287
|
-
expect(fixture.calls.prompt).toBe(1);
|
|
288
|
-
} finally {
|
|
289
|
-
runtime.stop();
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('dispatches v2 session.prompt with stable continuation id and metadata', async () => {
|
|
294
|
-
const promptBodies = [];
|
|
295
|
-
const messages = [
|
|
296
|
-
{ info: { id: 'msg-user', role: 'user' }, parts: [] },
|
|
297
|
-
{
|
|
298
|
-
info: {
|
|
299
|
-
id: 'msg-done',
|
|
300
|
-
role: 'assistant',
|
|
301
|
-
time: { completed: 200 },
|
|
302
|
-
providerID: 'p',
|
|
303
|
-
modelID: 'm',
|
|
304
|
-
tokens: { input: 10, output: 5, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
305
|
-
},
|
|
306
|
-
parts: [{ type: 'text', text: 'done: 一二三' }],
|
|
307
|
-
},
|
|
308
|
-
];
|
|
309
|
-
const session = buildSession();
|
|
310
|
-
session.metadata.yuri.goal.createdAt = 1;
|
|
311
|
-
const fetchImpl = async (input, init = {}) => {
|
|
312
|
-
const url = String(input);
|
|
313
|
-
const reqPath = url.split('?')[0];
|
|
314
|
-
if (pathEndsWith(reqPath, '/session/status')) {
|
|
315
|
-
return jsonResponse({ 'ses-goal': { type: 'idle' } });
|
|
316
|
-
}
|
|
317
|
-
if (pathEndsWith(reqPath, '/session/active')) {
|
|
318
|
-
return jsonResponse({ data: {} });
|
|
319
|
-
}
|
|
320
|
-
if (pathEndsWith(reqPath, '/session/ses-goal/message')) {
|
|
321
|
-
return jsonResponse({ data: new URL(url).searchParams.get('order') === 'desc' ? [...messages].reverse() : messages, cursor: {} });
|
|
322
|
-
}
|
|
323
|
-
if (pathEndsWith(reqPath, '/session/ses-goal') && !reqPath.includes('/message')) {
|
|
324
|
-
if (init.method === 'PATCH' && init.body) {
|
|
325
|
-
const body = JSON.parse(init.body);
|
|
326
|
-
session.metadata = body.metadata;
|
|
327
|
-
}
|
|
328
|
-
return jsonResponse(reqPath.includes('/api/') ? { data: session } : session);
|
|
329
|
-
}
|
|
330
|
-
if (pathEndsWith(reqPath, '/model') || pathEndsWith(reqPath, '/agent')) {
|
|
331
|
-
return emptyResponse(204);
|
|
332
|
-
}
|
|
333
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
334
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
335
|
-
return jsonResponse({
|
|
336
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
return jsonResponse(reqPath.includes('/api/') ? { data: session } : session);
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
await withFetch(fetchImpl, async () => {
|
|
343
|
-
const runtime = createSessionGoalRuntime({
|
|
344
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
345
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
346
|
-
getSmallModelService: async () => ({
|
|
347
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"still going"}' }),
|
|
348
|
-
}),
|
|
349
|
-
idleQuietMs: 1_000_000,
|
|
350
|
-
kickoffQuietMs: 1,
|
|
351
|
-
maxAutoTurns: 20,
|
|
352
|
-
});
|
|
353
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
354
|
-
expect(promptBodies.length).toBeGreaterThan(0);
|
|
355
|
-
const body = promptBodies[0];
|
|
356
|
-
expect(body.id).toBe(buildContinuationMessageID({ goalId: 'goal-1', generation: 0, turnsUsed: 1 }));
|
|
357
|
-
expect(body.id.startsWith('msg_')).toBe(true);
|
|
358
|
-
const SessionMessage = await loadInstalledSessionMessageSchema();
|
|
359
|
-
expect(SessionMessage.ID.make(body.id)).toBe(body.id);
|
|
360
|
-
expect(String(body.text)).toContain('Continue working toward the active session goal.');
|
|
361
|
-
expect(body.metadata?.yuri?.goalContinuation).toBe(true);
|
|
362
|
-
// User-boundary prompt: synthetic lives in metadata only (not type: synthetic).
|
|
363
|
-
expect(body.metadata?.yuri?.synthetic).toBe(true);
|
|
364
|
-
expect(body.type).not.toBe('synthetic');
|
|
365
|
-
expect(runtime.getDispatchedContinuation('ses-goal')).toMatchObject({
|
|
366
|
-
goalId: 'goal-1',
|
|
367
|
-
generation: 0,
|
|
368
|
-
turnsUsed: 1,
|
|
369
|
-
messageID: body.id,
|
|
370
|
-
phase: 'accepted',
|
|
371
|
-
});
|
|
372
|
-
runtime.stop();
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
describe('session-goal token accounting', () => {
|
|
378
|
-
it('sums per-turn spend and ignores cache.read', () => {
|
|
379
|
-
expect(messageTokenSpend({
|
|
380
|
-
tokens: { input: 100, output: 50, reasoning: 10, cache: { read: 9999, write: 20 } },
|
|
381
|
-
})).toBe(180);
|
|
382
|
-
|
|
383
|
-
const first = accountGoalTokenSpend({
|
|
384
|
-
goal: { tokensUsed: 0, lastAccountedMessageID: '', createdAt: 1_000 },
|
|
385
|
-
messages: [
|
|
386
|
-
{
|
|
387
|
-
info: {
|
|
388
|
-
id: 'msg-pre',
|
|
389
|
-
role: 'assistant',
|
|
390
|
-
time: { completed: 500 },
|
|
391
|
-
tokens: { input: 1_000, output: 200, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
392
|
-
},
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
info: {
|
|
396
|
-
id: 'msg-a',
|
|
397
|
-
role: 'assistant',
|
|
398
|
-
time: { completed: 1_500 },
|
|
399
|
-
tokens: { input: 100, output: 40, reasoning: 5, cache: { read: 800, write: 10 } },
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
info: {
|
|
404
|
-
id: 'msg-b',
|
|
405
|
-
role: 'assistant',
|
|
406
|
-
time: { completed: 2_000 },
|
|
407
|
-
tokens: { input: 120, output: 30, reasoning: 0, cache: { read: 900, write: 0 } },
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
],
|
|
411
|
-
});
|
|
412
|
-
// Pre-goal msg-pre skipped; msg-a 155 + msg-b 150.
|
|
413
|
-
expect(first.tokensUsed).toBe(305);
|
|
414
|
-
expect(first.lastAccountedMessageID).toBe('msg-b');
|
|
415
|
-
|
|
416
|
-
const second = accountGoalTokenSpend({
|
|
417
|
-
goal: { tokensUsed: first.tokensUsed, lastAccountedMessageID: first.lastAccountedMessageID, createdAt: 1_000 },
|
|
418
|
-
messages: [
|
|
419
|
-
{
|
|
420
|
-
info: {
|
|
421
|
-
id: 'msg-b',
|
|
422
|
-
role: 'assistant',
|
|
423
|
-
time: { completed: 2_000 },
|
|
424
|
-
tokens: { input: 120, output: 30, reasoning: 0, cache: { read: 900, write: 0 } },
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
info: {
|
|
429
|
-
id: 'msg-c',
|
|
430
|
-
role: 'assistant',
|
|
431
|
-
time: { completed: 2_500 },
|
|
432
|
-
tokens: { input: 50, output: 25, reasoning: 0, cache: { read: 1_000, write: 5 } },
|
|
433
|
-
},
|
|
434
|
-
},
|
|
435
|
-
],
|
|
436
|
-
});
|
|
437
|
-
// Only msg-c is new: 80 more.
|
|
438
|
-
expect(second.tokensUsed).toBe(385);
|
|
439
|
-
expect(second.lastAccountedMessageID).toBe('msg-c');
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it('skips summary turns but advances the cursor', () => {
|
|
443
|
-
const result = accountGoalTokenSpend({
|
|
444
|
-
goal: { tokensUsed: 100, lastAccountedMessageID: 'msg-a', createdAt: 1_000 },
|
|
445
|
-
messages: [
|
|
446
|
-
{
|
|
447
|
-
info: {
|
|
448
|
-
id: 'msg-summary',
|
|
449
|
-
role: 'assistant',
|
|
450
|
-
summary: true,
|
|
451
|
-
time: { completed: 2_000 },
|
|
452
|
-
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
],
|
|
456
|
-
});
|
|
457
|
-
expect(result.tokensUsed).toBe(100);
|
|
458
|
-
expect(result.lastAccountedMessageID).toBe('msg-summary');
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
describe('session-goal runtime — restart-orphan quiescence', () => {
|
|
463
|
-
it('resumes past an orphaned incomplete assistant message when the session is idle', async () => {
|
|
464
|
-
const { fetch, calls } = makeFetch({
|
|
465
|
-
messages: [
|
|
466
|
-
{ info: { id: 'msg-user', role: 'user' }, parts: [] },
|
|
467
|
-
orphanIncompleteAssistant,
|
|
468
|
-
],
|
|
469
|
-
liveStatus: 'idle',
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
await withFetch(fetch, async () => {
|
|
473
|
-
const runtime = makeRuntime();
|
|
474
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
475
|
-
expect(calls.prompt + calls.promptAsync).toBeGreaterThan(0);
|
|
476
|
-
runtime.stop();
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it('still bails on an orphaned incomplete message when the session is genuinely busy', async () => {
|
|
481
|
-
const { fetch, calls } = makeFetch({
|
|
482
|
-
messages: [
|
|
483
|
-
{ info: { id: 'msg-user', role: 'user' }, parts: [] },
|
|
484
|
-
orphanIncompleteAssistant,
|
|
485
|
-
],
|
|
486
|
-
liveStatus: 'busy',
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
await withFetch(fetch, async () => {
|
|
490
|
-
const runtime = makeRuntime();
|
|
491
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
492
|
-
expect(calls.prompt + calls.promptAsync).toBe(0);
|
|
493
|
-
runtime.stop();
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
it('resumes normally when the tail assistant is complete (no regression)', async () => {
|
|
498
|
-
const { fetch, calls } = makeFetch({
|
|
499
|
-
messages: [
|
|
500
|
-
{ info: { id: 'msg-user', role: 'user' }, parts: [] },
|
|
501
|
-
{ info: { id: 'msg-done', role: 'assistant', time: { completed: 200 }, providerID: 'p', modelID: 'm' }, parts: [] },
|
|
502
|
-
],
|
|
503
|
-
liveStatus: 'idle',
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
await withFetch(fetch, async () => {
|
|
507
|
-
const runtime = makeRuntime();
|
|
508
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
509
|
-
expect(calls.prompt + calls.promptAsync).toBeGreaterThan(0);
|
|
510
|
-
runtime.stop();
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
const questionAskedPayload = (sessionID = 'ses-goal') => ({
|
|
516
|
-
type: 'question.asked',
|
|
517
|
-
properties: {
|
|
518
|
-
id: 'que_1',
|
|
519
|
-
sessionID,
|
|
520
|
-
questions: [{ question: 'Push?', header: 'Push', options: [{ label: 'Yes', description: '' }] }],
|
|
521
|
-
},
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
const flushQuestionPause = () => new Promise((resolve) => setTimeout(resolve, 50));
|
|
525
|
-
|
|
526
|
-
describe('session-goal runtime — pause for question', () => {
|
|
527
|
-
it('arms on native completion and cancels on native start, retry, question and shutdown', async () => {
|
|
528
|
-
vi.useFakeTimers();
|
|
529
|
-
const shouldKeepGoalActiveForQuestion = vi.fn(() => true);
|
|
530
|
-
const runtime = createSessionGoalRuntime({ buildOpenCodeUrl: (p) => `http://opencode${p}`, getOpenCodeAuthHeaders: () => ({}), idleQuietMs: 100, shouldKeepGoalActiveForQuestion });
|
|
531
|
-
try {
|
|
532
|
-
for (const [type, data] of [
|
|
533
|
-
['session.execution.started', {}],
|
|
534
|
-
['session.retry.scheduled', {}],
|
|
535
|
-
['session.execution.interrupted', { reason: 'shutdown' }],
|
|
536
|
-
['form.created', { form: { metadata: { kind: 'question' } } }],
|
|
537
|
-
]) {
|
|
538
|
-
runtime.processPayload({ type: 'session.execution.succeeded', data: { sessionID: 's' } }, '/repo');
|
|
539
|
-
expect(vi.getTimerCount()).toBe(1);
|
|
540
|
-
runtime.processPayload({ type, data: { sessionID: 's', ...data } }, '/repo');
|
|
541
|
-
expect(vi.getTimerCount()).toBe(0);
|
|
542
|
-
}
|
|
543
|
-
runtime.processPayload({ type: 'session.execution.failed', data: { sessionID: 's' } }, '/repo');
|
|
544
|
-
expect(vi.getTimerCount()).toBe(1);
|
|
545
|
-
runtime.processPayload({ type: 'form.created', data: { sessionID: 's', form: { metadata: { kind: 'other' } } } }, '/repo');
|
|
546
|
-
expect(vi.getTimerCount()).toBe(1);
|
|
547
|
-
expect(shouldKeepGoalActiveForQuestion).toHaveBeenCalledTimes(1);
|
|
548
|
-
} finally { runtime.stop(); vi.useRealTimers(); }
|
|
549
|
-
});
|
|
550
|
-
it.each([false, true])('patches an active goal to paused without sending a continuation (native: %s)', async (native) => {
|
|
551
|
-
const patches = [];
|
|
552
|
-
const calls = { promptAsync: 0, abort: 0 };
|
|
553
|
-
const session = buildSession('active');
|
|
554
|
-
const fetchImpl = async (input, init = {}) => {
|
|
555
|
-
const url = String(input);
|
|
556
|
-
const path = url.split('?')[0];
|
|
557
|
-
if (path.includes('/abort')) {
|
|
558
|
-
calls.abort += 1;
|
|
559
|
-
return new Response(JSON.stringify({}), { status: 200 });
|
|
560
|
-
}
|
|
561
|
-
if (path.endsWith('/prompt_async')) {
|
|
562
|
-
calls.promptAsync += 1;
|
|
563
|
-
return new Response(JSON.stringify({}), { status: 200 });
|
|
564
|
-
}
|
|
565
|
-
if (path.endsWith('/session/ses-goal')) {
|
|
566
|
-
if (init.method === 'PATCH') {
|
|
567
|
-
const body = JSON.parse(init.body || '{}');
|
|
568
|
-
patches.push(body);
|
|
569
|
-
session.metadata = body.metadata;
|
|
570
|
-
}
|
|
571
|
-
return new Response(JSON.stringify(session), { status: 200 });
|
|
572
|
-
}
|
|
573
|
-
return new Response(JSON.stringify(session), { status: 200 });
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
await withFetch(fetchImpl, async () => {
|
|
577
|
-
const runtime = makeRuntime();
|
|
578
|
-
runtime.processPayload(native ? { type: 'form.created', data: { form: { sessionID: 'ses-goal', metadata: { kind: 'question' } } } } : questionAskedPayload(), '/repo');
|
|
579
|
-
await flushQuestionPause();
|
|
580
|
-
expect(patches.length).toBe(1);
|
|
581
|
-
expect(patches[0].metadata.yuri.goal.status).toBe('paused');
|
|
582
|
-
expect(patches[0].metadata.yuri.goal.statusReason).toBe('paused for question');
|
|
583
|
-
expect(calls.promptAsync).toBe(0);
|
|
584
|
-
expect(calls.abort).toBe(0);
|
|
585
|
-
runtime.stop();
|
|
586
|
-
});
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
it('does not PATCH a session that has no goal', async () => {
|
|
590
|
-
let patchCount = 0;
|
|
591
|
-
const session = { id: 'ses-goal', directory: '/repo' };
|
|
592
|
-
const fetchImpl = async (input, init = {}) => {
|
|
593
|
-
const path = String(input).split('?')[0];
|
|
594
|
-
if (path.endsWith('/session/ses-goal') && init.method === 'PATCH') {
|
|
595
|
-
patchCount += 1;
|
|
596
|
-
}
|
|
597
|
-
return new Response(JSON.stringify(session), { status: 200 });
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
await withFetch(fetchImpl, async () => {
|
|
601
|
-
const runtime = makeRuntime();
|
|
602
|
-
runtime.processPayload(questionAskedPayload(), '/repo');
|
|
603
|
-
await flushQuestionPause();
|
|
604
|
-
expect(patchCount).toBe(0);
|
|
605
|
-
runtime.stop();
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
it('does not change an already paused goal', async () => {
|
|
610
|
-
const patches = [];
|
|
611
|
-
const session = buildSession('paused');
|
|
612
|
-
const fetchImpl = async (input, init = {}) => {
|
|
613
|
-
const path = String(input).split('?')[0];
|
|
614
|
-
if (path.endsWith('/session/ses-goal') && init.method === 'PATCH') {
|
|
615
|
-
patches.push(JSON.parse(init.body || '{}'));
|
|
616
|
-
}
|
|
617
|
-
return new Response(JSON.stringify(session), { status: 200 });
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
await withFetch(fetchImpl, async () => {
|
|
621
|
-
const runtime = makeRuntime();
|
|
622
|
-
runtime.processPayload(questionAskedPayload(), '/repo');
|
|
623
|
-
await flushQuestionPause();
|
|
624
|
-
expect(patches.length).toBe(0);
|
|
625
|
-
expect(session.metadata.yuri.goal.status).toBe('paused');
|
|
626
|
-
runtime.stop();
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
it('pauses the parent session goal when a child session asks a question', async () => {
|
|
631
|
-
const patches = [];
|
|
632
|
-
const child = { id: 'ses-child', parentID: 'ses-goal', directory: '/repo' };
|
|
633
|
-
const parent = buildSession('active');
|
|
634
|
-
const fetchImpl = async (input, init = {}) => {
|
|
635
|
-
const path = String(input).split('?')[0];
|
|
636
|
-
if (path.endsWith('/session/ses-child')) {
|
|
637
|
-
return new Response(JSON.stringify(child), { status: 200 });
|
|
638
|
-
}
|
|
639
|
-
if (path.endsWith('/session/ses-goal')) {
|
|
640
|
-
if (init.method === 'PATCH') {
|
|
641
|
-
const body = JSON.parse(init.body || '{}');
|
|
642
|
-
patches.push(body);
|
|
643
|
-
parent.metadata = body.metadata;
|
|
644
|
-
}
|
|
645
|
-
return new Response(JSON.stringify(parent), { status: 200 });
|
|
646
|
-
}
|
|
647
|
-
return new Response(JSON.stringify(parent), { status: 200 });
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
await withFetch(fetchImpl, async () => {
|
|
651
|
-
const runtime = makeRuntime();
|
|
652
|
-
runtime.processPayload(questionAskedPayload('ses-child'), '/repo');
|
|
653
|
-
await flushQuestionPause();
|
|
654
|
-
expect(patches.length).toBe(1);
|
|
655
|
-
expect(patches[0].metadata.yuri.goal.status).toBe('paused');
|
|
656
|
-
expect(patches[0].metadata.yuri.goal.statusReason).toBe('paused for question');
|
|
657
|
-
runtime.stop();
|
|
658
|
-
});
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
it('keeps the goal active when question auto-delegate will handle the ask', async () => {
|
|
662
|
-
const patches = [];
|
|
663
|
-
const session = buildSession('active');
|
|
664
|
-
const fetchImpl = async (input, init = {}) => {
|
|
665
|
-
const path = String(input).split('?')[0];
|
|
666
|
-
if (path.endsWith('/session/ses-goal') && init.method === 'PATCH') {
|
|
667
|
-
patches.push(JSON.parse(init.body || '{}'));
|
|
668
|
-
}
|
|
669
|
-
return new Response(JSON.stringify(session), { status: 200 });
|
|
670
|
-
};
|
|
671
|
-
|
|
672
|
-
await withFetch(fetchImpl, async () => {
|
|
673
|
-
const runtime = createSessionGoalRuntime({
|
|
674
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
675
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
676
|
-
getSmallModelService: async () => ({
|
|
677
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"in progress"}' }),
|
|
678
|
-
}),
|
|
679
|
-
idleQuietMs: 1_000_000,
|
|
680
|
-
kickoffQuietMs: 1,
|
|
681
|
-
shouldKeepGoalActiveForQuestion: () => true,
|
|
682
|
-
});
|
|
683
|
-
runtime.processPayload(questionAskedPayload(), '/repo');
|
|
684
|
-
await flushQuestionPause();
|
|
685
|
-
expect(patches.length).toBe(0);
|
|
686
|
-
expect(session.metadata.yuri.goal.status).toBe('active');
|
|
687
|
-
runtime.stop();
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
it('pauses the root owner goal when a grandchild session asks a question', async () => {
|
|
692
|
-
const patches = [];
|
|
693
|
-
const grand = { id: 'ses-grand', parentID: 'ses-child', directory: '/repo/wt' };
|
|
694
|
-
const child = { id: 'ses-child', parentID: 'ses-goal', directory: '/repo/wt' };
|
|
695
|
-
const parent = buildSession('active');
|
|
696
|
-
parent.directory = '/repo';
|
|
697
|
-
const fetchImpl = async (input, init = {}) => {
|
|
698
|
-
const path = String(input).split('?')[0];
|
|
699
|
-
if (path.endsWith('/session/ses-grand')) {
|
|
700
|
-
return new Response(JSON.stringify(grand), { status: 200 });
|
|
701
|
-
}
|
|
702
|
-
if (path.endsWith('/session/ses-child')) {
|
|
703
|
-
return new Response(JSON.stringify(child), { status: 200 });
|
|
704
|
-
}
|
|
705
|
-
if (path.endsWith('/session/ses-goal')) {
|
|
706
|
-
if (init.method === 'PATCH') {
|
|
707
|
-
const body = JSON.parse(init.body || '{}');
|
|
708
|
-
patches.push(body);
|
|
709
|
-
parent.metadata = body.metadata;
|
|
710
|
-
}
|
|
711
|
-
return new Response(JSON.stringify(parent), { status: 200 });
|
|
712
|
-
}
|
|
713
|
-
return new Response(JSON.stringify(parent), { status: 200 });
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
await withFetch(fetchImpl, async () => {
|
|
717
|
-
const runtime = makeRuntime();
|
|
718
|
-
runtime.processPayload(questionAskedPayload('ses-grand'), '/repo/wt');
|
|
719
|
-
await flushQuestionPause();
|
|
720
|
-
expect(patches.length).toBe(1);
|
|
721
|
-
expect(patches[0].metadata.yuri.goal.status).toBe('paused');
|
|
722
|
-
runtime.stop();
|
|
723
|
-
});
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
it('notifies onGoalPaused after abort so question timers can reverse-pause', async () => {
|
|
727
|
-
const paused = [];
|
|
728
|
-
const session = buildSession('active');
|
|
729
|
-
const fetchImpl = async (input, init = {}) => {
|
|
730
|
-
const path = String(input).split('?')[0];
|
|
731
|
-
if (path.endsWith('/session/ses-goal') && init.method === 'PATCH') {
|
|
732
|
-
const body = JSON.parse(init.body || '{}');
|
|
733
|
-
session.metadata = body.metadata;
|
|
734
|
-
}
|
|
735
|
-
return new Response(JSON.stringify(session), { status: 200 });
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
await withFetch(fetchImpl, async () => {
|
|
739
|
-
const runtime = createSessionGoalRuntime({
|
|
740
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
741
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
742
|
-
getSmallModelService: async () => ({
|
|
743
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
|
|
744
|
-
}),
|
|
745
|
-
idleQuietMs: 1_000_000,
|
|
746
|
-
kickoffQuietMs: 1,
|
|
747
|
-
onGoalPaused: (sessionId, directory) => {
|
|
748
|
-
paused.push({ sessionId, directory });
|
|
749
|
-
},
|
|
750
|
-
});
|
|
751
|
-
runtime.processPayload({
|
|
752
|
-
type: 'message.updated',
|
|
753
|
-
properties: {
|
|
754
|
-
info: {
|
|
755
|
-
role: 'assistant',
|
|
756
|
-
sessionID: 'ses-goal',
|
|
757
|
-
error: { name: 'MessageAbortedError' },
|
|
758
|
-
},
|
|
759
|
-
},
|
|
760
|
-
}, '/repo');
|
|
761
|
-
await flushQuestionPause();
|
|
762
|
-
expect(session.metadata.yuri.goal.status).toBe('paused');
|
|
763
|
-
expect(paused).toEqual([{ sessionId: 'ses-goal', directory: '/repo' }]);
|
|
764
|
-
runtime.stop();
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
it('notifies onGoalPaused when metadata lands paused before abort (UI race)', async () => {
|
|
769
|
-
const paused = [];
|
|
770
|
-
const session = buildSession('paused');
|
|
771
|
-
session.metadata.yuri.goal.statusReason = 'paused by user';
|
|
772
|
-
const fetchImpl = async () => new Response(JSON.stringify(session), { status: 200 });
|
|
773
|
-
|
|
774
|
-
await withFetch(fetchImpl, async () => {
|
|
775
|
-
const runtime = createSessionGoalRuntime({
|
|
776
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
777
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
778
|
-
getSmallModelService: async () => ({
|
|
779
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
|
|
780
|
-
}),
|
|
781
|
-
idleQuietMs: 1_000_000,
|
|
782
|
-
kickoffQuietMs: 1,
|
|
783
|
-
onGoalPaused: (sessionId, directory) => {
|
|
784
|
-
paused.push({ sessionId, directory });
|
|
785
|
-
},
|
|
786
|
-
});
|
|
787
|
-
// Abort arrives after UI already wrote paused metadata — must still notify.
|
|
788
|
-
runtime.processPayload({
|
|
789
|
-
type: 'message.updated',
|
|
790
|
-
properties: {
|
|
791
|
-
info: {
|
|
792
|
-
role: 'assistant',
|
|
793
|
-
sessionID: 'ses-goal',
|
|
794
|
-
error: { name: 'MessageAbortedError' },
|
|
795
|
-
},
|
|
796
|
-
},
|
|
797
|
-
}, '/repo');
|
|
798
|
-
await flushQuestionPause();
|
|
799
|
-
expect(paused).toEqual([{ sessionId: 'ses-goal', directory: '/repo' }]);
|
|
800
|
-
runtime.stop();
|
|
801
|
-
});
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
it('session.updated paused-by-user notifies onGoalPaused; question pause does not', async () => {
|
|
805
|
-
const paused = [];
|
|
806
|
-
const userPaused = buildSession('paused');
|
|
807
|
-
userPaused.metadata.yuri.goal.statusReason = 'paused by user';
|
|
808
|
-
const questionPaused = buildSession('paused');
|
|
809
|
-
questionPaused.metadata.yuri.goal.statusReason = 'paused for question';
|
|
810
|
-
|
|
811
|
-
const makeRuntime = (session) => createSessionGoalRuntime({
|
|
812
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
813
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
814
|
-
getSmallModelService: async () => ({
|
|
815
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
|
|
816
|
-
}),
|
|
817
|
-
idleQuietMs: 1_000_000,
|
|
818
|
-
kickoffQuietMs: 1,
|
|
819
|
-
onGoalPaused: (sessionId, directory) => {
|
|
820
|
-
paused.push({ sessionId, directory, reason: session.metadata.yuri.goal.statusReason });
|
|
821
|
-
},
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
await withFetch(async () => new Response(JSON.stringify(userPaused), { status: 200 }), async () => {
|
|
825
|
-
const runtime = makeRuntime(userPaused);
|
|
826
|
-
runtime.processPayload({
|
|
827
|
-
type: 'session.updated',
|
|
828
|
-
properties: { info: userPaused },
|
|
829
|
-
}, '/repo');
|
|
830
|
-
await flushQuestionPause();
|
|
831
|
-
expect(paused).toEqual([{
|
|
832
|
-
sessionId: 'ses-goal',
|
|
833
|
-
directory: '/repo',
|
|
834
|
-
reason: 'paused by user',
|
|
835
|
-
}]);
|
|
836
|
-
runtime.stop();
|
|
837
|
-
});
|
|
838
|
-
|
|
839
|
-
paused.length = 0;
|
|
840
|
-
await withFetch(async () => new Response(JSON.stringify(questionPaused), { status: 200 }), async () => {
|
|
841
|
-
const runtime = makeRuntime(questionPaused);
|
|
842
|
-
runtime.processPayload({
|
|
843
|
-
type: 'session.updated',
|
|
844
|
-
properties: { info: questionPaused },
|
|
845
|
-
}, '/repo');
|
|
846
|
-
await flushQuestionPause();
|
|
847
|
-
// Question-driven pause must preserve auto-delegate timers.
|
|
848
|
-
expect(paused).toEqual([]);
|
|
849
|
-
runtime.stop();
|
|
850
|
-
});
|
|
851
|
-
});
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
describe('session-goal execution generation helpers', () => {
|
|
855
|
-
it('advances generation on pause, resume, and condition changes — not on settle', () => {
|
|
856
|
-
const base = {
|
|
857
|
-
id: 'g1',
|
|
858
|
-
status: 'active',
|
|
859
|
-
executionGeneration: 2,
|
|
860
|
-
tokenBudget: 100,
|
|
861
|
-
objective: 'x',
|
|
862
|
-
objectiveFile: false,
|
|
863
|
-
};
|
|
864
|
-
expect(shouldAdvanceGoalExecutionGeneration(base, { ...base, status: 'paused' })).toBe(true);
|
|
865
|
-
expect(shouldAdvanceGoalExecutionGeneration(
|
|
866
|
-
{ ...base, status: 'paused' },
|
|
867
|
-
{ ...base, status: 'active' },
|
|
868
|
-
)).toBe(true);
|
|
869
|
-
expect(shouldAdvanceGoalExecutionGeneration(base, { ...base, tokenBudget: 200 })).toBe(true);
|
|
870
|
-
expect(shouldAdvanceGoalExecutionGeneration(base, { ...base, status: 'complete' })).toBe(false);
|
|
871
|
-
expect(readGoalExecutionGeneration({})).toBe(0);
|
|
872
|
-
expect(withGoalExecutionGeneration(base, { ...base, status: 'paused' }).executionGeneration).toBe(3);
|
|
873
|
-
});
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
describe('session-goal runtime — Host metadata store seams', () => {
|
|
877
|
-
it('writes through mutateSessionMetadata and never PATCHes OpenCode metadata when seams are injected', async () => {
|
|
878
|
-
const active = buildSession('active');
|
|
879
|
-
const goal = active.metadata.yuri.goal;
|
|
880
|
-
const metadata = {
|
|
881
|
-
yuri: {
|
|
882
|
-
goal: { ...goal, executionGeneration: 0 },
|
|
883
|
-
assist: { recap: 'keep-me' },
|
|
884
|
-
},
|
|
885
|
-
};
|
|
886
|
-
const readSessionMetadata = vi.fn(async () => metadata);
|
|
887
|
-
const mutateSessionMetadata = vi.fn(async (_sessionId, decide) => {
|
|
888
|
-
const decision = decide(metadata);
|
|
889
|
-
if (!decision?.ok) return { committed: false, reason: decision?.reason, metadata };
|
|
890
|
-
metadata.yuri = {
|
|
891
|
-
...metadata.yuri,
|
|
892
|
-
...(decision.patch.yuri || {}),
|
|
893
|
-
goal: {
|
|
894
|
-
...metadata.yuri.goal,
|
|
895
|
-
...(decision.patch.yuri?.goal || {}),
|
|
896
|
-
},
|
|
897
|
-
};
|
|
898
|
-
return { committed: true, metadata };
|
|
899
|
-
});
|
|
900
|
-
const fetchMock = vi.fn(async (input, init = {}) => {
|
|
901
|
-
const url = String(input);
|
|
902
|
-
const reqPath = url.split('?')[0];
|
|
903
|
-
if (init.method === 'PATCH') {
|
|
904
|
-
throw new Error(`OpenCode metadata PATCH must not run when store seams are wired: ${reqPath}`);
|
|
905
|
-
}
|
|
906
|
-
// resolveGoalOwner walks parentID via GET /session/:id
|
|
907
|
-
if (reqPath.endsWith('/session/ses-goal')) {
|
|
908
|
-
return new Response(JSON.stringify({ id: 'ses-goal', directory: '/repo' }), { status: 200 });
|
|
909
|
-
}
|
|
910
|
-
return new Response(JSON.stringify({}), { status: 200 });
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
await withFetch(fetchMock, async () => {
|
|
914
|
-
const runtime = createSessionGoalRuntime({
|
|
915
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
916
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
917
|
-
getSmallModelService: async () => {
|
|
918
|
-
throw new Error('small model must not run');
|
|
919
|
-
},
|
|
920
|
-
idleQuietMs: 1_000_000,
|
|
921
|
-
kickoffQuietMs: 1,
|
|
922
|
-
maxAutoTurns: 20,
|
|
923
|
-
readSessionMetadata,
|
|
924
|
-
persistSessionGoal: async () => {
|
|
925
|
-
throw new Error('persistSessionGoal must not run when mutate is wired');
|
|
926
|
-
},
|
|
927
|
-
mutateSessionMetadata,
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
await runtime.pauseForQuestion('ses-goal', '/repo');
|
|
931
|
-
|
|
932
|
-
expect(readSessionMetadata).toHaveBeenCalledWith('ses-goal');
|
|
933
|
-
expect(mutateSessionMetadata).toHaveBeenCalledTimes(1);
|
|
934
|
-
expect(metadata.yuri.goal).toMatchObject({
|
|
935
|
-
id: goal.id,
|
|
936
|
-
status: 'paused',
|
|
937
|
-
statusReason: 'paused for question',
|
|
938
|
-
executionGeneration: 1,
|
|
939
|
-
});
|
|
940
|
-
// Neighbouring Host namespaces must survive the goal write.
|
|
941
|
-
expect(metadata.yuri.assist).toEqual({ recap: 'keep-me' });
|
|
942
|
-
expect(fetchMock.mock.calls.some(([, init]) => init?.method === 'PATCH')).toBe(false);
|
|
943
|
-
runtime.stop();
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
describe('session-goal runtime — pause / audit / dispatch boundary', () => {
|
|
949
|
-
const makeTempStore = async () => {
|
|
950
|
-
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-goal-race-'));
|
|
951
|
-
const store = createSessionMetadataStore({ dataDir });
|
|
952
|
-
await store.load();
|
|
953
|
-
return {
|
|
954
|
-
store,
|
|
955
|
-
dataDir,
|
|
956
|
-
cleanup: () => fs.rmSync(dataDir, { recursive: true, force: true }),
|
|
957
|
-
};
|
|
958
|
-
};
|
|
959
|
-
|
|
960
|
-
const idleMessages = [
|
|
961
|
-
{ info: { id: 'msg-user', role: 'user' }, parts: [] },
|
|
962
|
-
{
|
|
963
|
-
info: {
|
|
964
|
-
id: 'msg-done',
|
|
965
|
-
role: 'assistant',
|
|
966
|
-
agent: 'build',
|
|
967
|
-
time: { completed: 200 },
|
|
968
|
-
providerID: 'p',
|
|
969
|
-
modelID: 'm',
|
|
970
|
-
tokens: { input: 10, output: 5, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
971
|
-
},
|
|
972
|
-
parts: [{ type: 'text', text: 'working' }],
|
|
973
|
-
},
|
|
974
|
-
];
|
|
975
|
-
|
|
976
|
-
/**
|
|
977
|
-
* @param {object} [options]
|
|
978
|
-
* @param {Array|object} [options.messages]
|
|
979
|
-
* @param {Set<string>|string[]} [options.knownMessageIDs] exact ids found via message GET / inbox
|
|
980
|
-
* @param {boolean} [options.messageLookupUnavailable] fail != empty for reconcile
|
|
981
|
-
* @param {(body: object) => Response|Promise<Response>} [options.onPrompt]
|
|
982
|
-
*/
|
|
983
|
-
const makeOpenCodeFetch = (messagesOrOptions = idleMessages) => {
|
|
984
|
-
const options = Array.isArray(messagesOrOptions) || (messagesOrOptions && messagesOrOptions.data)
|
|
985
|
-
? { messages: messagesOrOptions }
|
|
986
|
-
: (messagesOrOptions || {});
|
|
987
|
-
const messages = options.messages ?? idleMessages;
|
|
988
|
-
const knownMessageIDs = options.knownMessageIDs instanceof Set
|
|
989
|
-
? options.knownMessageIDs
|
|
990
|
-
: new Set(options.knownMessageIDs || []);
|
|
991
|
-
const messageLookupUnavailable = options.messageLookupUnavailable === true;
|
|
992
|
-
const onPrompt = typeof options.onPrompt === 'function' ? options.onPrompt : null;
|
|
993
|
-
|
|
994
|
-
return async (input, init = {}) => {
|
|
995
|
-
const url = String(input);
|
|
996
|
-
const reqPath = url.split('?')[0];
|
|
997
|
-
if (pathEndsWith(reqPath, '/session/status')) {
|
|
998
|
-
return jsonResponse({ 'ses-goal': { type: 'idle' } });
|
|
999
|
-
}
|
|
1000
|
-
if (pathEndsWith(reqPath, '/session/active')) {
|
|
1001
|
-
return jsonResponse({ data: {} });
|
|
1002
|
-
}
|
|
1003
|
-
// Exact message GET before list suffix match.
|
|
1004
|
-
const exactMatch = reqPath.match(/\/session\/ses-goal\/message\/([^/?]+)$/);
|
|
1005
|
-
if (exactMatch) {
|
|
1006
|
-
if (messageLookupUnavailable) {
|
|
1007
|
-
return new Response(JSON.stringify({ error: 'upstream' }), {
|
|
1008
|
-
status: 500,
|
|
1009
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
const messageID = decodeURIComponent(exactMatch[1]);
|
|
1013
|
-
if (knownMessageIDs.has(messageID)) {
|
|
1014
|
-
return jsonResponse({ id: messageID, type: 'user', text: 'continuation' });
|
|
1015
|
-
}
|
|
1016
|
-
return new Response(JSON.stringify({ error: 'not found' }), {
|
|
1017
|
-
status: 404,
|
|
1018
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
if (pathEndsWith(reqPath, '/session/ses-goal/inbox') || pathEndsWith(reqPath, '/inbox')) {
|
|
1022
|
-
if (messageLookupUnavailable) {
|
|
1023
|
-
return new Response(JSON.stringify({ error: 'upstream' }), {
|
|
1024
|
-
status: 500,
|
|
1025
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
return jsonResponse({
|
|
1029
|
-
data: [...knownMessageIDs].map((id) => ({ id, type: 'user', sessionID: 'ses-goal' })),
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
if (pathEndsWith(reqPath, '/session/ses-goal/message')) {
|
|
1033
|
-
// Support both bare array fixtures and official `{ data, cursor }` projection.
|
|
1034
|
-
const body = Array.isArray(messages)
|
|
1035
|
-
? { data: messages, cursor: {} }
|
|
1036
|
-
: messages;
|
|
1037
|
-
return jsonResponse(new URL(String(input)).searchParams.get('order') === 'desc'
|
|
1038
|
-
? { ...body, data: [...body.data].reverse() }
|
|
1039
|
-
: body);
|
|
1040
|
-
}
|
|
1041
|
-
if (pathEndsWith(reqPath, '/session/ses-goal')) {
|
|
1042
|
-
if (init.method === 'PATCH') {
|
|
1043
|
-
throw new Error('OpenCode PATCH must not run with Host store');
|
|
1044
|
-
}
|
|
1045
|
-
return jsonResponse({ data: { id: 'ses-goal', directory: '/repo' } });
|
|
1046
|
-
}
|
|
1047
|
-
if (pathEndsWith(reqPath, '/model') || pathEndsWith(reqPath, '/agent')) {
|
|
1048
|
-
return emptyResponse(204);
|
|
1049
|
-
}
|
|
1050
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1051
|
-
const body = JSON.parse(init.body || '{}');
|
|
1052
|
-
if (onPrompt) return onPrompt(body);
|
|
1053
|
-
if (body.id) knownMessageIDs.add(body.id);
|
|
1054
|
-
return jsonResponse({
|
|
1055
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
return jsonResponse({});
|
|
1059
|
-
};
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
it('audit start → user pause → late continue does not dispatch or raise turnsUsed', async () => {
|
|
1063
|
-
const { store, cleanup } = await makeTempStore();
|
|
1064
|
-
const goal = {
|
|
1065
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1066
|
-
executionGeneration: 0,
|
|
1067
|
-
createdAt: 1,
|
|
1068
|
-
turnsUsed: 3,
|
|
1069
|
-
};
|
|
1070
|
-
await store.setSessionMetadata('ses-goal', {
|
|
1071
|
-
yuri: { goal, assist: { recap: 'keep' }, archive: { archivedAt: 9 } },
|
|
1072
|
-
}, { allowArchive: true });
|
|
1073
|
-
|
|
1074
|
-
let releaseAudit;
|
|
1075
|
-
const auditGate = new Promise((resolve) => { releaseAudit = resolve; });
|
|
1076
|
-
const promptBodies = [];
|
|
1077
|
-
|
|
1078
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1079
|
-
const runtime = createSessionGoalRuntime({
|
|
1080
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1081
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1082
|
-
getSmallModelService: async () => ({
|
|
1083
|
-
generateSmallModelText: async () => {
|
|
1084
|
-
await auditGate;
|
|
1085
|
-
return { text: '{"verdict":"continue","note":"late"}' };
|
|
1086
|
-
},
|
|
1087
|
-
}),
|
|
1088
|
-
idleQuietMs: 1_000_000,
|
|
1089
|
-
kickoffQuietMs: 1,
|
|
1090
|
-
maxAutoTurns: 20,
|
|
1091
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1092
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1093
|
-
persistSessionGoal: async () => {
|
|
1094
|
-
throw new Error('unexpected persistSessionGoal');
|
|
1095
|
-
},
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
// Intercept prompt via fetch override that already returns ok — count via monkeypatch.
|
|
1099
|
-
const originalFetch = globalThis.fetch;
|
|
1100
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1101
|
-
const reqPath = String(input).split('?')[0];
|
|
1102
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1103
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1104
|
-
return jsonResponse({
|
|
1105
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
return originalFetch(input, init);
|
|
1109
|
-
};
|
|
1110
|
-
|
|
1111
|
-
try {
|
|
1112
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1113
|
-
// Let the tick reach the audit gate.
|
|
1114
|
-
await new Promise((r) => setTimeout(r, 30));
|
|
1115
|
-
expect(runtime.getDispatchEpoch('ses-goal')).toBe(0);
|
|
1116
|
-
|
|
1117
|
-
const paused = await runtime.pauseGoal('ses-goal', '/repo', 'paused by user');
|
|
1118
|
-
expect(paused.status).toBe('paused');
|
|
1119
|
-
expect(paused.executionGeneration).toBe(1);
|
|
1120
|
-
expect(runtime.getDispatchEpoch('ses-goal')).toBeGreaterThan(0);
|
|
1121
|
-
|
|
1122
|
-
// Readers only see committed pause (store already published).
|
|
1123
|
-
const mid = await store.get('ses-goal');
|
|
1124
|
-
expect(mid.yuri.goal.status).toBe('paused');
|
|
1125
|
-
expect(mid.yuri.assist).toEqual({ recap: 'keep' });
|
|
1126
|
-
expect(mid.yuri.archive).toEqual({ archivedAt: 9 });
|
|
1127
|
-
|
|
1128
|
-
releaseAudit();
|
|
1129
|
-
await tickPromise;
|
|
1130
|
-
|
|
1131
|
-
expect(promptBodies).toEqual([]);
|
|
1132
|
-
const finalMeta = await store.get('ses-goal');
|
|
1133
|
-
expect(finalMeta.yuri.goal.status).toBe('paused');
|
|
1134
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(3);
|
|
1135
|
-
expect(finalMeta.yuri.goal.executionGeneration).toBe(1);
|
|
1136
|
-
expect(finalMeta.yuri.assist).toEqual({ recap: 'keep' });
|
|
1137
|
-
expect(finalMeta.yuri.archive).toEqual({ archivedAt: 9 });
|
|
1138
|
-
runtime.stop();
|
|
1139
|
-
} finally {
|
|
1140
|
-
globalThis.fetch = originalFetch;
|
|
1141
|
-
cleanup();
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1144
|
-
});
|
|
1145
|
-
|
|
1146
|
-
it('late audit complete after pause cannot settle the goal', async () => {
|
|
1147
|
-
const { store, cleanup } = await makeTempStore();
|
|
1148
|
-
const goal = {
|
|
1149
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1150
|
-
executionGeneration: 4,
|
|
1151
|
-
createdAt: 1,
|
|
1152
|
-
turnsUsed: 1,
|
|
1153
|
-
};
|
|
1154
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1155
|
-
|
|
1156
|
-
let releaseAudit;
|
|
1157
|
-
const auditGate = new Promise((resolve) => { releaseAudit = resolve; });
|
|
1158
|
-
|
|
1159
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1160
|
-
const runtime = createSessionGoalRuntime({
|
|
1161
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1162
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1163
|
-
getSmallModelService: async () => ({
|
|
1164
|
-
generateSmallModelText: async () => {
|
|
1165
|
-
await auditGate;
|
|
1166
|
-
return { text: '{"verdict":"complete","note":"done"}' };
|
|
1167
|
-
},
|
|
1168
|
-
}),
|
|
1169
|
-
idleQuietMs: 1_000_000,
|
|
1170
|
-
kickoffQuietMs: 1,
|
|
1171
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1172
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1173
|
-
});
|
|
1174
|
-
|
|
1175
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1176
|
-
await new Promise((r) => setTimeout(r, 30));
|
|
1177
|
-
await runtime.pauseGoal('ses-goal', '/repo', 'paused by user');
|
|
1178
|
-
releaseAudit();
|
|
1179
|
-
await tickPromise;
|
|
1180
|
-
|
|
1181
|
-
const finalMeta = await store.get('ses-goal');
|
|
1182
|
-
expect(finalMeta.yuri.goal.status).toBe('paused');
|
|
1183
|
-
expect(finalMeta.yuri.goal.executionGeneration).toBe(5);
|
|
1184
|
-
runtime.stop();
|
|
1185
|
-
cleanup();
|
|
1186
|
-
});
|
|
1187
|
-
});
|
|
1188
|
-
|
|
1189
|
-
it('resume advances generation so a prior-period continue cannot commit', async () => {
|
|
1190
|
-
const { store, cleanup } = await makeTempStore();
|
|
1191
|
-
const goal = {
|
|
1192
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1193
|
-
executionGeneration: 1,
|
|
1194
|
-
createdAt: 1,
|
|
1195
|
-
turnsUsed: 2,
|
|
1196
|
-
};
|
|
1197
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1198
|
-
|
|
1199
|
-
let releaseAudit;
|
|
1200
|
-
const auditGate = new Promise((resolve) => { releaseAudit = resolve; });
|
|
1201
|
-
const promptBodies = [];
|
|
1202
|
-
|
|
1203
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1204
|
-
const originalFetch = globalThis.fetch;
|
|
1205
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1206
|
-
const reqPath = String(input).split('?')[0];
|
|
1207
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1208
|
-
promptBodies.push(1);
|
|
1209
|
-
return jsonResponse({
|
|
1210
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
return originalFetch(input, init);
|
|
1214
|
-
};
|
|
1215
|
-
|
|
1216
|
-
try {
|
|
1217
|
-
const runtime = createSessionGoalRuntime({
|
|
1218
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1219
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1220
|
-
getSmallModelService: async () => ({
|
|
1221
|
-
generateSmallModelText: async () => {
|
|
1222
|
-
await auditGate;
|
|
1223
|
-
return { text: '{"verdict":"continue","note":"old"}' };
|
|
1224
|
-
},
|
|
1225
|
-
}),
|
|
1226
|
-
idleQuietMs: 1_000_000,
|
|
1227
|
-
kickoffQuietMs: 1,
|
|
1228
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1229
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1230
|
-
});
|
|
1231
|
-
|
|
1232
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1233
|
-
await new Promise((r) => setTimeout(r, 30));
|
|
1234
|
-
// Simulate pause then resume while audit is in flight (new generation).
|
|
1235
|
-
await runtime.pauseGoal('ses-goal', '/repo', 'paused by user');
|
|
1236
|
-
await store.mutateSessionMetadata('ses-goal', (current) => {
|
|
1237
|
-
const g = current.yuri.goal;
|
|
1238
|
-
return {
|
|
1239
|
-
ok: true,
|
|
1240
|
-
patch: {
|
|
1241
|
-
yuri: {
|
|
1242
|
-
goal: {
|
|
1243
|
-
...g,
|
|
1244
|
-
status: 'active',
|
|
1245
|
-
statusReason: 'resumed',
|
|
1246
|
-
executionGeneration: g.executionGeneration + 1,
|
|
1247
|
-
},
|
|
1248
|
-
},
|
|
1249
|
-
},
|
|
1250
|
-
};
|
|
1251
|
-
});
|
|
1252
|
-
// Local epoch was bumped on pause; resume does not lower it.
|
|
1253
|
-
releaseAudit();
|
|
1254
|
-
await tickPromise;
|
|
1255
|
-
expect(promptBodies).toEqual([]);
|
|
1256
|
-
const finalMeta = await store.get('ses-goal');
|
|
1257
|
-
expect(finalMeta.yuri.goal.status).toBe('active');
|
|
1258
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(2);
|
|
1259
|
-
expect(finalMeta.yuri.goal.executionGeneration).toBe(3);
|
|
1260
|
-
runtime.stop();
|
|
1261
|
-
} finally {
|
|
1262
|
-
globalThis.fetch = originalFetch;
|
|
1263
|
-
cleanup();
|
|
1264
|
-
}
|
|
1265
|
-
});
|
|
1266
|
-
});
|
|
1267
|
-
|
|
1268
|
-
it('successful continue commits turnsUsed and records dispatch identity', async () => {
|
|
1269
|
-
const { store, cleanup } = await makeTempStore();
|
|
1270
|
-
const goal = {
|
|
1271
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1272
|
-
executionGeneration: 0,
|
|
1273
|
-
createdAt: 1,
|
|
1274
|
-
turnsUsed: 0,
|
|
1275
|
-
statusReason: 'resumed',
|
|
1276
|
-
};
|
|
1277
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1278
|
-
const promptBodies = [];
|
|
1279
|
-
|
|
1280
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1281
|
-
const originalFetch = globalThis.fetch;
|
|
1282
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1283
|
-
const reqPath = String(input).split('?')[0];
|
|
1284
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1285
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1286
|
-
return jsonResponse({
|
|
1287
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
return originalFetch(input, init);
|
|
1291
|
-
};
|
|
1292
|
-
try {
|
|
1293
|
-
const runtime = createSessionGoalRuntime({
|
|
1294
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1295
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1296
|
-
getSmallModelService: async () => ({
|
|
1297
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1298
|
-
}),
|
|
1299
|
-
idleQuietMs: 1_000_000,
|
|
1300
|
-
kickoffQuietMs: 1,
|
|
1301
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1302
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1303
|
-
});
|
|
1304
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1305
|
-
expect(promptBodies.length).toBe(1);
|
|
1306
|
-
expect(promptBodies[0].id).toBe(buildContinuationMessageID({
|
|
1307
|
-
goalId: goal.id,
|
|
1308
|
-
generation: 0,
|
|
1309
|
-
turnsUsed: 1,
|
|
1310
|
-
}));
|
|
1311
|
-
const finalMeta = await store.get('ses-goal');
|
|
1312
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(1);
|
|
1313
|
-
expect(finalMeta.yuri.goal.pendingContinuation == null).toBe(true);
|
|
1314
|
-
expect(runtime.getDispatchedContinuation('ses-goal')).toMatchObject({
|
|
1315
|
-
goalId: goal.id,
|
|
1316
|
-
generation: 0,
|
|
1317
|
-
turnsUsed: 1,
|
|
1318
|
-
messageID: promptBodies[0].id,
|
|
1319
|
-
phase: 'accepted',
|
|
1320
|
-
});
|
|
1321
|
-
runtime.stop();
|
|
1322
|
-
} finally {
|
|
1323
|
-
globalThis.fetch = originalFetch;
|
|
1324
|
-
cleanup();
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
});
|
|
1328
|
-
|
|
1329
|
-
it('raw v2 projection payload + duplicate continuation id skips second dispatch', async () => {
|
|
1330
|
-
const { store, cleanup } = await makeTempStore();
|
|
1331
|
-
const goal = {
|
|
1332
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1333
|
-
executionGeneration: 0,
|
|
1334
|
-
createdAt: 1,
|
|
1335
|
-
turnsUsed: 0,
|
|
1336
|
-
statusReason: 'resumed',
|
|
1337
|
-
};
|
|
1338
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1339
|
-
|
|
1340
|
-
// Official raw SessionMessageInfo (no info/parts wrapper).
|
|
1341
|
-
const rawProjection = {
|
|
1342
|
-
data: [
|
|
1343
|
-
{ id: 'msg-user', type: 'user', text: 'hi', time: { created: 1 } },
|
|
1344
|
-
{
|
|
1345
|
-
id: 'msg-done',
|
|
1346
|
-
type: 'assistant',
|
|
1347
|
-
agent: 'build',
|
|
1348
|
-
model: { id: 'm', providerID: 'p' },
|
|
1349
|
-
time: { created: 2, completed: 200 },
|
|
1350
|
-
content: [{ type: 'text', text: 'working' }],
|
|
1351
|
-
tokens: { input: 10, output: 5, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
1352
|
-
},
|
|
1353
|
-
],
|
|
1354
|
-
cursor: {},
|
|
1355
|
-
};
|
|
1356
|
-
const promptBodies = [];
|
|
1357
|
-
const knownMessageIDs = new Set();
|
|
1358
|
-
|
|
1359
|
-
await withFetch(makeOpenCodeFetch({ messages: rawProjection, knownMessageIDs }), async () => {
|
|
1360
|
-
const originalFetch = globalThis.fetch;
|
|
1361
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1362
|
-
const reqPath = String(input).split('?')[0];
|
|
1363
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1364
|
-
const body = JSON.parse(init.body || '{}');
|
|
1365
|
-
promptBodies.push(body);
|
|
1366
|
-
if (body.id) knownMessageIDs.add(body.id);
|
|
1367
|
-
return jsonResponse({
|
|
1368
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
return originalFetch(input, init);
|
|
1372
|
-
};
|
|
1373
|
-
try {
|
|
1374
|
-
const runtime = createSessionGoalRuntime({
|
|
1375
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1376
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1377
|
-
getSmallModelService: async () => ({
|
|
1378
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1379
|
-
}),
|
|
1380
|
-
idleQuietMs: 1_000_000,
|
|
1381
|
-
kickoffQuietMs: 1,
|
|
1382
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1383
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1384
|
-
});
|
|
1385
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1386
|
-
expect(promptBodies.length).toBe(1);
|
|
1387
|
-
const firstId = promptBodies[0].id;
|
|
1388
|
-
expect(firstId).toBe(buildContinuationMessageID({ goalId: goal.id, generation: 0, turnsUsed: 1 }));
|
|
1389
|
-
// Simulate crash after accept: turnsUsed rolled back but upstream still
|
|
1390
|
-
// holds the fixed message id — reconcile counts once, no second prompt.
|
|
1391
|
-
await store.mutateSessionMetadata('ses-goal', (current) => ({
|
|
1392
|
-
ok: true,
|
|
1393
|
-
patch: {
|
|
1394
|
-
yuri: {
|
|
1395
|
-
goal: { ...current.yuri.goal, turnsUsed: 0 },
|
|
1396
|
-
},
|
|
1397
|
-
},
|
|
1398
|
-
}));
|
|
1399
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1400
|
-
expect(promptBodies.length).toBe(1);
|
|
1401
|
-
const finalMeta = await store.get('ses-goal');
|
|
1402
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(1);
|
|
1403
|
-
expect(finalMeta.yuri.goal.pendingContinuation == null).toBe(true);
|
|
1404
|
-
runtime.stop();
|
|
1405
|
-
} finally {
|
|
1406
|
-
globalThis.fetch = originalFetch;
|
|
1407
|
-
cleanup();
|
|
1408
|
-
}
|
|
1409
|
-
});
|
|
1410
|
-
});
|
|
1411
|
-
|
|
1412
|
-
it('shutdown interrupt blocks auto-continue until authoritative idle', async () => {
|
|
1413
|
-
const { store, cleanup } = await makeTempStore();
|
|
1414
|
-
const goal = {
|
|
1415
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1416
|
-
executionGeneration: 0,
|
|
1417
|
-
createdAt: 1,
|
|
1418
|
-
turnsUsed: 0,
|
|
1419
|
-
statusReason: 'resumed',
|
|
1420
|
-
};
|
|
1421
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1422
|
-
const promptBodies = [];
|
|
1423
|
-
|
|
1424
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1425
|
-
const originalFetch = globalThis.fetch;
|
|
1426
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1427
|
-
const reqPath = String(input).split('?')[0];
|
|
1428
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1429
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1430
|
-
return jsonResponse({
|
|
1431
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
return originalFetch(input, init);
|
|
1435
|
-
};
|
|
1436
|
-
try {
|
|
1437
|
-
const runtime = createSessionGoalRuntime({
|
|
1438
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1439
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1440
|
-
getSmallModelService: async () => ({
|
|
1441
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1442
|
-
}),
|
|
1443
|
-
idleQuietMs: 1_000_000,
|
|
1444
|
-
kickoffQuietMs: 1,
|
|
1445
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1446
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1447
|
-
});
|
|
1448
|
-
runtime.processPayload({
|
|
1449
|
-
type: 'session.execution.interrupted',
|
|
1450
|
-
properties: { sessionID: 'ses-goal', reason: 'shutdown' },
|
|
1451
|
-
});
|
|
1452
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1453
|
-
expect(promptBodies).toEqual([]);
|
|
1454
|
-
// Authoritative idle clears recovery and allows continue.
|
|
1455
|
-
runtime.processPayload({
|
|
1456
|
-
type: 'session.status',
|
|
1457
|
-
properties: { sessionID: 'ses-goal', status: { type: 'idle' }, directory: '/repo' },
|
|
1458
|
-
});
|
|
1459
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1460
|
-
expect(promptBodies.length).toBe(1);
|
|
1461
|
-
runtime.stop();
|
|
1462
|
-
} finally {
|
|
1463
|
-
globalThis.fetch = originalFetch;
|
|
1464
|
-
cleanup();
|
|
1465
|
-
}
|
|
1466
|
-
});
|
|
1467
|
-
});
|
|
1468
|
-
|
|
1469
|
-
it('pause during switchAgent drops before prompt with zero transport identity', async () => {
|
|
1470
|
-
const { store, cleanup } = await makeTempStore();
|
|
1471
|
-
const goal = {
|
|
1472
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1473
|
-
executionGeneration: 0,
|
|
1474
|
-
createdAt: 1,
|
|
1475
|
-
turnsUsed: 0,
|
|
1476
|
-
statusReason: 'resumed',
|
|
1477
|
-
};
|
|
1478
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1479
|
-
|
|
1480
|
-
let releaseAgent;
|
|
1481
|
-
const agentGate = new Promise((resolve) => { releaseAgent = resolve; });
|
|
1482
|
-
let agentStarted = false;
|
|
1483
|
-
const promptBodies = [];
|
|
1484
|
-
|
|
1485
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1486
|
-
const originalFetch = globalThis.fetch;
|
|
1487
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1488
|
-
const reqPath = String(input).split('?')[0];
|
|
1489
|
-
if (pathEndsWith(reqPath, '/agent')) {
|
|
1490
|
-
agentStarted = true;
|
|
1491
|
-
await agentGate;
|
|
1492
|
-
return emptyResponse(204);
|
|
1493
|
-
}
|
|
1494
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1495
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1496
|
-
return jsonResponse({
|
|
1497
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1498
|
-
});
|
|
1499
|
-
}
|
|
1500
|
-
return originalFetch(input, init);
|
|
1501
|
-
};
|
|
1502
|
-
|
|
1503
|
-
try {
|
|
1504
|
-
const runtime = createSessionGoalRuntime({
|
|
1505
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1506
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1507
|
-
getSmallModelService: async () => ({
|
|
1508
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1509
|
-
}),
|
|
1510
|
-
idleQuietMs: 1_000_000,
|
|
1511
|
-
kickoffQuietMs: 1,
|
|
1512
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1513
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1514
|
-
});
|
|
1515
|
-
|
|
1516
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1517
|
-
const started = Date.now();
|
|
1518
|
-
while (!agentStarted) {
|
|
1519
|
-
if (Date.now() - started > 2000) throw new Error('switchAgent never started');
|
|
1520
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
1521
|
-
}
|
|
1522
|
-
// Selection in flight: transport must not be claimed yet.
|
|
1523
|
-
expect(runtime.getDispatchedContinuation('ses-goal')).toBeNull();
|
|
1524
|
-
|
|
1525
|
-
const paused = await runtime.pauseGoal('ses-goal', '/repo', 'paused by user');
|
|
1526
|
-
expect(paused.status).toBe('paused');
|
|
1527
|
-
expect(runtime.getDispatchEpoch('ses-goal')).toBeGreaterThan(0);
|
|
1528
|
-
|
|
1529
|
-
releaseAgent();
|
|
1530
|
-
await tickPromise;
|
|
1531
|
-
|
|
1532
|
-
expect(promptBodies).toEqual([]);
|
|
1533
|
-
expect(runtime.getDispatchedContinuation('ses-goal')).toBeNull();
|
|
1534
|
-
const finalMeta = await store.get('ses-goal');
|
|
1535
|
-
expect(finalMeta.yuri.goal.status).toBe('paused');
|
|
1536
|
-
// Before selection/prompt: turnsUsed must stay 0 and reserved pending cleared.
|
|
1537
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(0);
|
|
1538
|
-
expect(finalMeta.yuri.goal.pendingContinuation == null).toBe(true);
|
|
1539
|
-
runtime.stop();
|
|
1540
|
-
} finally {
|
|
1541
|
-
globalThis.fetch = originalFetch;
|
|
1542
|
-
cleanup();
|
|
1543
|
-
}
|
|
1544
|
-
});
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
it('pause during switchModel drops before prompt with zero transport identity', async () => {
|
|
1548
|
-
const { store, cleanup } = await makeTempStore();
|
|
1549
|
-
const goal = {
|
|
1550
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1551
|
-
executionGeneration: 0,
|
|
1552
|
-
createdAt: 1,
|
|
1553
|
-
turnsUsed: 0,
|
|
1554
|
-
statusReason: 'resumed',
|
|
1555
|
-
};
|
|
1556
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1557
|
-
|
|
1558
|
-
let releaseModel;
|
|
1559
|
-
const modelGate = new Promise((resolve) => { releaseModel = resolve; });
|
|
1560
|
-
let modelStarted = false;
|
|
1561
|
-
const promptBodies = [];
|
|
1562
|
-
|
|
1563
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1564
|
-
const originalFetch = globalThis.fetch;
|
|
1565
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1566
|
-
const reqPath = String(input).split('?')[0];
|
|
1567
|
-
if (pathEndsWith(reqPath, '/model')) {
|
|
1568
|
-
modelStarted = true;
|
|
1569
|
-
await modelGate;
|
|
1570
|
-
return emptyResponse(204);
|
|
1571
|
-
}
|
|
1572
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1573
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1574
|
-
return jsonResponse({
|
|
1575
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1576
|
-
});
|
|
1577
|
-
}
|
|
1578
|
-
return originalFetch(input, init);
|
|
1579
|
-
};
|
|
1580
|
-
|
|
1581
|
-
try {
|
|
1582
|
-
const runtime = createSessionGoalRuntime({
|
|
1583
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1584
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1585
|
-
getSmallModelService: async () => ({
|
|
1586
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1587
|
-
}),
|
|
1588
|
-
idleQuietMs: 1_000_000,
|
|
1589
|
-
kickoffQuietMs: 1,
|
|
1590
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1591
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1592
|
-
});
|
|
1593
|
-
|
|
1594
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1595
|
-
const started = Date.now();
|
|
1596
|
-
while (!modelStarted) {
|
|
1597
|
-
if (Date.now() - started > 2000) throw new Error('switchModel never started');
|
|
1598
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
1599
|
-
}
|
|
1600
|
-
expect(runtime.getDispatchedContinuation('ses-goal')).toBeNull();
|
|
1601
|
-
|
|
1602
|
-
await runtime.pauseGoal('ses-goal', '/repo', 'paused by user');
|
|
1603
|
-
releaseModel();
|
|
1604
|
-
await tickPromise;
|
|
1605
|
-
|
|
1606
|
-
expect(promptBodies).toEqual([]);
|
|
1607
|
-
expect(runtime.getDispatchedContinuation('ses-goal')).toBeNull();
|
|
1608
|
-
runtime.stop();
|
|
1609
|
-
} finally {
|
|
1610
|
-
globalThis.fetch = originalFetch;
|
|
1611
|
-
cleanup();
|
|
1612
|
-
}
|
|
1613
|
-
});
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
it('shutdown during switchAgent drops before prompt without uncertain phase', async () => {
|
|
1617
|
-
const { store, cleanup } = await makeTempStore();
|
|
1618
|
-
const goal = {
|
|
1619
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1620
|
-
executionGeneration: 0,
|
|
1621
|
-
createdAt: 1,
|
|
1622
|
-
turnsUsed: 0,
|
|
1623
|
-
statusReason: 'resumed',
|
|
1624
|
-
};
|
|
1625
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1626
|
-
|
|
1627
|
-
let releaseAgent;
|
|
1628
|
-
const agentGate = new Promise((resolve) => { releaseAgent = resolve; });
|
|
1629
|
-
let agentStarted = false;
|
|
1630
|
-
const promptBodies = [];
|
|
1631
|
-
|
|
1632
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1633
|
-
const originalFetch = globalThis.fetch;
|
|
1634
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1635
|
-
const reqPath = String(input).split('?')[0];
|
|
1636
|
-
if (pathEndsWith(reqPath, '/agent')) {
|
|
1637
|
-
agentStarted = true;
|
|
1638
|
-
await agentGate;
|
|
1639
|
-
return emptyResponse(204);
|
|
1640
|
-
}
|
|
1641
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1642
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1643
|
-
return jsonResponse({
|
|
1644
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
return originalFetch(input, init);
|
|
1648
|
-
};
|
|
1649
|
-
|
|
1650
|
-
try {
|
|
1651
|
-
const runtime = createSessionGoalRuntime({
|
|
1652
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1653
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1654
|
-
getSmallModelService: async () => ({
|
|
1655
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1656
|
-
}),
|
|
1657
|
-
idleQuietMs: 1_000_000,
|
|
1658
|
-
kickoffQuietMs: 1,
|
|
1659
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1660
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1661
|
-
});
|
|
1662
|
-
|
|
1663
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1664
|
-
const started = Date.now();
|
|
1665
|
-
while (!agentStarted) {
|
|
1666
|
-
if (Date.now() - started > 2000) throw new Error('switchAgent never started');
|
|
1667
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
runtime.processPayload({
|
|
1671
|
-
type: 'session.execution.interrupted',
|
|
1672
|
-
properties: { sessionID: 'ses-goal', reason: 'shutdown' },
|
|
1673
|
-
});
|
|
1674
|
-
releaseAgent();
|
|
1675
|
-
await tickPromise;
|
|
1676
|
-
|
|
1677
|
-
expect(promptBodies).toEqual([]);
|
|
1678
|
-
const dispatch = runtime.getDispatchedContinuation('ses-goal');
|
|
1679
|
-
expect(dispatch === null || dispatch.phase !== 'uncertain').toBe(true);
|
|
1680
|
-
runtime.stop();
|
|
1681
|
-
} finally {
|
|
1682
|
-
globalThis.fetch = originalFetch;
|
|
1683
|
-
cleanup();
|
|
1684
|
-
}
|
|
1685
|
-
});
|
|
1686
|
-
});
|
|
1687
|
-
|
|
1688
|
-
it('switchAgent selection failure is not reported as prompt-uncertain', async () => {
|
|
1689
|
-
const { store, cleanup } = await makeTempStore();
|
|
1690
|
-
const goal = {
|
|
1691
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1692
|
-
executionGeneration: 0,
|
|
1693
|
-
createdAt: 1,
|
|
1694
|
-
turnsUsed: 0,
|
|
1695
|
-
statusReason: 'resumed',
|
|
1696
|
-
};
|
|
1697
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1698
|
-
const promptBodies = [];
|
|
1699
|
-
|
|
1700
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1701
|
-
const originalFetch = globalThis.fetch;
|
|
1702
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1703
|
-
const reqPath = String(input).split('?')[0];
|
|
1704
|
-
if (pathEndsWith(reqPath, '/agent')) {
|
|
1705
|
-
return new Response(JSON.stringify({ error: 'agent unavailable' }), {
|
|
1706
|
-
status: 500,
|
|
1707
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1711
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1712
|
-
return jsonResponse({
|
|
1713
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1714
|
-
});
|
|
1715
|
-
}
|
|
1716
|
-
return originalFetch(input, init);
|
|
1717
|
-
};
|
|
1718
|
-
|
|
1719
|
-
try {
|
|
1720
|
-
const runtime = createSessionGoalRuntime({
|
|
1721
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1722
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1723
|
-
getSmallModelService: async () => ({
|
|
1724
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1725
|
-
}),
|
|
1726
|
-
idleQuietMs: 1_000_000,
|
|
1727
|
-
kickoffQuietMs: 1,
|
|
1728
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1729
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1730
|
-
});
|
|
1731
|
-
|
|
1732
|
-
await runtime.runTick('ses-goal', '/repo').catch(() => {});
|
|
1733
|
-
expect(promptBodies).toEqual([]);
|
|
1734
|
-
const dispatch = runtime.getDispatchedContinuation('ses-goal');
|
|
1735
|
-
expect(dispatch === null || dispatch.phase !== 'uncertain').toBe(true);
|
|
1736
|
-
runtime.stop();
|
|
1737
|
-
} finally {
|
|
1738
|
-
globalThis.fetch = originalFetch;
|
|
1739
|
-
cleanup();
|
|
1740
|
-
}
|
|
1741
|
-
});
|
|
1742
|
-
});
|
|
1743
|
-
|
|
1744
|
-
it('persist failure during pause keeps prior committed active state', async () => {
|
|
1745
|
-
const { store, cleanup } = await makeTempStore();
|
|
1746
|
-
const goal = {
|
|
1747
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1748
|
-
executionGeneration: 2,
|
|
1749
|
-
};
|
|
1750
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1751
|
-
|
|
1752
|
-
let failNext = false;
|
|
1753
|
-
const gated = {
|
|
1754
|
-
mutateSessionMetadata: async (id, decide) => {
|
|
1755
|
-
if (failNext) {
|
|
1756
|
-
failNext = false;
|
|
1757
|
-
throw new Error('disk full');
|
|
1758
|
-
}
|
|
1759
|
-
return store.mutateSessionMetadata(id, decide);
|
|
1760
|
-
},
|
|
1761
|
-
get: (id) => store.get(id),
|
|
1762
|
-
};
|
|
1763
|
-
|
|
1764
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1765
|
-
const runtime = createSessionGoalRuntime({
|
|
1766
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1767
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1768
|
-
getSmallModelService: async () => ({
|
|
1769
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
|
|
1770
|
-
}),
|
|
1771
|
-
idleQuietMs: 1_000_000,
|
|
1772
|
-
kickoffQuietMs: 1,
|
|
1773
|
-
readSessionMetadata: (id) => gated.get(id),
|
|
1774
|
-
mutateSessionMetadata: (id, decide) => gated.mutateSessionMetadata(id, decide),
|
|
1775
|
-
});
|
|
1776
|
-
|
|
1777
|
-
failNext = true;
|
|
1778
|
-
await expect(runtime.pauseGoal('ses-goal', '/repo', 'paused by user')).rejects.toThrow('disk full');
|
|
1779
|
-
// Local epoch still bumped (pause requested) but durable state unchanged.
|
|
1780
|
-
const mid = await store.get('ses-goal');
|
|
1781
|
-
expect(mid.yuri.goal.status).toBe('active');
|
|
1782
|
-
expect(mid.yuri.goal.executionGeneration).toBe(2);
|
|
1783
|
-
runtime.stop();
|
|
1784
|
-
cleanup();
|
|
1785
|
-
});
|
|
1786
|
-
});
|
|
1787
|
-
|
|
1788
|
-
it('before-selection pause keeps turnsUsed at 0 and clears reserved pending', async () => {
|
|
1789
|
-
const { store, cleanup } = await makeTempStore();
|
|
1790
|
-
const goal = {
|
|
1791
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1792
|
-
executionGeneration: 0,
|
|
1793
|
-
createdAt: 1,
|
|
1794
|
-
turnsUsed: 0,
|
|
1795
|
-
statusReason: 'resumed',
|
|
1796
|
-
};
|
|
1797
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1798
|
-
|
|
1799
|
-
let releaseAgent;
|
|
1800
|
-
const agentGate = new Promise((resolve) => { releaseAgent = resolve; });
|
|
1801
|
-
let agentStarted = false;
|
|
1802
|
-
const promptBodies = [];
|
|
1803
|
-
|
|
1804
|
-
await withFetch(makeOpenCodeFetch(), async () => {
|
|
1805
|
-
const originalFetch = globalThis.fetch;
|
|
1806
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1807
|
-
const reqPath = String(input).split('?')[0];
|
|
1808
|
-
if (pathEndsWith(reqPath, '/agent')) {
|
|
1809
|
-
agentStarted = true;
|
|
1810
|
-
await agentGate;
|
|
1811
|
-
return emptyResponse(204);
|
|
1812
|
-
}
|
|
1813
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1814
|
-
promptBodies.push(JSON.parse(init.body || '{}'));
|
|
1815
|
-
return jsonResponse({ data: { id: 'inbox_1' } });
|
|
1816
|
-
}
|
|
1817
|
-
return originalFetch(input, init);
|
|
1818
|
-
};
|
|
1819
|
-
try {
|
|
1820
|
-
const runtime = createSessionGoalRuntime({
|
|
1821
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1822
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1823
|
-
getSmallModelService: async () => ({
|
|
1824
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1825
|
-
}),
|
|
1826
|
-
idleQuietMs: 1_000_000,
|
|
1827
|
-
kickoffQuietMs: 1,
|
|
1828
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1829
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1830
|
-
});
|
|
1831
|
-
const tickPromise = runtime.runTick('ses-goal', '/repo');
|
|
1832
|
-
const started = Date.now();
|
|
1833
|
-
while (!agentStarted) {
|
|
1834
|
-
if (Date.now() - started > 2000) throw new Error('switchAgent never started');
|
|
1835
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
1836
|
-
}
|
|
1837
|
-
// Reserved pending should exist before selection completes.
|
|
1838
|
-
const mid = await store.get('ses-goal');
|
|
1839
|
-
expect(mid.yuri.goal.turnsUsed).toBe(0);
|
|
1840
|
-
expect(parsePendingContinuation(mid.yuri.goal.pendingContinuation)?.phase).toBe('reserved');
|
|
1841
|
-
|
|
1842
|
-
await runtime.pauseGoal('ses-goal', '/repo', 'paused by user');
|
|
1843
|
-
releaseAgent();
|
|
1844
|
-
await tickPromise;
|
|
1845
|
-
|
|
1846
|
-
expect(promptBodies).toEqual([]);
|
|
1847
|
-
const finalMeta = await store.get('ses-goal');
|
|
1848
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(0);
|
|
1849
|
-
expect(finalMeta.yuri.goal.pendingContinuation == null).toBe(true);
|
|
1850
|
-
expect(finalMeta.yuri.goal.status).toBe('paused');
|
|
1851
|
-
runtime.stop();
|
|
1852
|
-
} finally {
|
|
1853
|
-
globalThis.fetch = originalFetch;
|
|
1854
|
-
cleanup();
|
|
1855
|
-
}
|
|
1856
|
-
});
|
|
1857
|
-
});
|
|
1858
|
-
|
|
1859
|
-
it('persist failure after accept keeps accepted pending and reboot counts once', async () => {
|
|
1860
|
-
const { store, cleanup } = await makeTempStore();
|
|
1861
|
-
const messageID = buildContinuationMessageID({ goalId: 'goal-1', generation: 0, turnsUsed: 1 });
|
|
1862
|
-
const knownMessageIDs = new Set([messageID]);
|
|
1863
|
-
// Durable state after accept + crash before turnsUsed commit.
|
|
1864
|
-
await store.setSessionMetadata('ses-goal', {
|
|
1865
|
-
yuri: {
|
|
1866
|
-
goal: {
|
|
1867
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1868
|
-
executionGeneration: 0,
|
|
1869
|
-
createdAt: 1,
|
|
1870
|
-
turnsUsed: 0,
|
|
1871
|
-
statusReason: 'resumed',
|
|
1872
|
-
pendingContinuation: buildPendingContinuation({
|
|
1873
|
-
messageID,
|
|
1874
|
-
goalId: 'goal-1',
|
|
1875
|
-
generation: 0,
|
|
1876
|
-
turnsUsed: 1,
|
|
1877
|
-
phase: 'accepted',
|
|
1878
|
-
text: 'Continue working toward the active session goal.',
|
|
1879
|
-
providerID: 'p',
|
|
1880
|
-
modelID: 'm',
|
|
1881
|
-
agent: 'build',
|
|
1882
|
-
}),
|
|
1883
|
-
},
|
|
1884
|
-
},
|
|
1885
|
-
});
|
|
1886
|
-
let promptCount = 0;
|
|
1887
|
-
|
|
1888
|
-
await withFetch(makeOpenCodeFetch({ knownMessageIDs }), async () => {
|
|
1889
|
-
const originalFetch = globalThis.fetch;
|
|
1890
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1891
|
-
const reqPath = String(input).split('?')[0];
|
|
1892
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1893
|
-
promptCount += 1;
|
|
1894
|
-
return jsonResponse({
|
|
1895
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
1896
|
-
});
|
|
1897
|
-
}
|
|
1898
|
-
return originalFetch(input, init);
|
|
1899
|
-
};
|
|
1900
|
-
try {
|
|
1901
|
-
const meta = await store.get('ses-goal');
|
|
1902
|
-
expect(parsePendingContinuation(meta.yuri.goal.pendingContinuation)?.phase).toBe('accepted');
|
|
1903
|
-
expect(meta.yuri.goal.turnsUsed).toBe(0);
|
|
1904
|
-
|
|
1905
|
-
// Fresh runtime = reboot: reconcile finds message, counts once, no blind new id.
|
|
1906
|
-
const runtime = createSessionGoalRuntime({
|
|
1907
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1908
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1909
|
-
getSmallModelService: async () => ({
|
|
1910
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1911
|
-
}),
|
|
1912
|
-
idleQuietMs: 1_000_000,
|
|
1913
|
-
kickoffQuietMs: 1,
|
|
1914
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1915
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1916
|
-
});
|
|
1917
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1918
|
-
const after = await store.get('ses-goal');
|
|
1919
|
-
expect(after.yuri.goal.turnsUsed).toBe(1);
|
|
1920
|
-
expect(after.yuri.goal.pendingContinuation == null).toBe(true);
|
|
1921
|
-
expect(promptCount).toBe(0);
|
|
1922
|
-
runtime.stop();
|
|
1923
|
-
} finally {
|
|
1924
|
-
globalThis.fetch = originalFetch;
|
|
1925
|
-
cleanup();
|
|
1926
|
-
}
|
|
1927
|
-
});
|
|
1928
|
-
});
|
|
1929
|
-
|
|
1930
|
-
it('transport drop after accept pauses with stable identity and reboot reconciles', async () => {
|
|
1931
|
-
const { store, cleanup } = await makeTempStore();
|
|
1932
|
-
const goal = {
|
|
1933
|
-
...buildSession('active').metadata.yuri.goal,
|
|
1934
|
-
executionGeneration: 0,
|
|
1935
|
-
createdAt: 1,
|
|
1936
|
-
turnsUsed: 0,
|
|
1937
|
-
statusReason: 'resumed',
|
|
1938
|
-
};
|
|
1939
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
1940
|
-
const knownMessageIDs = new Set();
|
|
1941
|
-
let promptAttempts = 0;
|
|
1942
|
-
|
|
1943
|
-
await withFetch(makeOpenCodeFetch({ knownMessageIDs }), async () => {
|
|
1944
|
-
const originalFetch = globalThis.fetch;
|
|
1945
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
1946
|
-
const reqPath = String(input).split('?')[0];
|
|
1947
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
1948
|
-
promptAttempts += 1;
|
|
1949
|
-
const body = JSON.parse(init.body || '{}');
|
|
1950
|
-
// Simulate: upstream accepted the id, then transport dropped the response.
|
|
1951
|
-
if (body.id) knownMessageIDs.add(body.id);
|
|
1952
|
-
throw new Error('socket hang up after accept');
|
|
1953
|
-
}
|
|
1954
|
-
return originalFetch(input, init);
|
|
1955
|
-
};
|
|
1956
|
-
try {
|
|
1957
|
-
const runtime = createSessionGoalRuntime({
|
|
1958
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1959
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1960
|
-
getSmallModelService: async () => ({
|
|
1961
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1962
|
-
}),
|
|
1963
|
-
idleQuietMs: 1_000_000,
|
|
1964
|
-
kickoffQuietMs: 1,
|
|
1965
|
-
readSessionMetadata: (id) => store.get(id),
|
|
1966
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
1967
|
-
});
|
|
1968
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
1969
|
-
const mid = await store.get('ses-goal');
|
|
1970
|
-
expect(mid.yuri.goal.status).toBe('paused');
|
|
1971
|
-
expect(String(mid.yuri.goal.statusReason)).toMatch(/uncertain|continuation/i);
|
|
1972
|
-
const pending = parsePendingContinuation(mid.yuri.goal.pendingContinuation);
|
|
1973
|
-
expect(pending).toBeTruthy();
|
|
1974
|
-
expect(pending.messageID).toMatch(/^msg_goalc_/);
|
|
1975
|
-
expect(mid.yuri.goal.turnsUsed).toBe(0);
|
|
1976
|
-
expect(promptAttempts).toBe(1);
|
|
1977
|
-
|
|
1978
|
-
// Reboot + resume: reconcile finds the message, counts once, no second prompt.
|
|
1979
|
-
runtime.stop();
|
|
1980
|
-
await store.mutateSessionMetadata('ses-goal', (current) => ({
|
|
1981
|
-
ok: true,
|
|
1982
|
-
patch: {
|
|
1983
|
-
yuri: {
|
|
1984
|
-
goal: {
|
|
1985
|
-
...current.yuri.goal,
|
|
1986
|
-
status: 'active',
|
|
1987
|
-
statusReason: 'resumed',
|
|
1988
|
-
executionGeneration: current.yuri.goal.executionGeneration + 1,
|
|
1989
|
-
},
|
|
1990
|
-
},
|
|
1991
|
-
},
|
|
1992
|
-
}));
|
|
1993
|
-
// Keep pending with original generation for stale-gen found path.
|
|
1994
|
-
const runtime2 = createSessionGoalRuntime({
|
|
1995
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
1996
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
1997
|
-
getSmallModelService: async () => ({
|
|
1998
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
1999
|
-
}),
|
|
2000
|
-
idleQuietMs: 1_000_000,
|
|
2001
|
-
kickoffQuietMs: 1,
|
|
2002
|
-
readSessionMetadata: (id) => store.get(id),
|
|
2003
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
2004
|
-
});
|
|
2005
|
-
await runtime2.runTick('ses-goal', '/repo');
|
|
2006
|
-
const after = await store.get('ses-goal');
|
|
2007
|
-
// Found under stale gen → counted once; may continue a new turn after.
|
|
2008
|
-
expect(after.yuri.goal.turnsUsed).toBeGreaterThanOrEqual(1);
|
|
2009
|
-
expect(after.yuri.goal.pendingContinuation == null
|
|
2010
|
-
|| after.yuri.goal.turnsUsed >= 1).toBe(true);
|
|
2011
|
-
runtime2.stop();
|
|
2012
|
-
} finally {
|
|
2013
|
-
globalThis.fetch = originalFetch;
|
|
2014
|
-
cleanup();
|
|
2015
|
-
}
|
|
2016
|
-
});
|
|
2017
|
-
});
|
|
2018
|
-
|
|
2019
|
-
it('reboot with reserved pending re-dispatches same message id and fixed payload', async () => {
|
|
2020
|
-
const { store, cleanup } = await makeTempStore();
|
|
2021
|
-
const messageID = buildContinuationMessageID({ goalId: 'goal-1', generation: 0, turnsUsed: 1 });
|
|
2022
|
-
const fixedText = 'Continue working toward the active session goal.\nFIXED-PAYLOAD-MARKER';
|
|
2023
|
-
const pending = buildPendingContinuation({
|
|
2024
|
-
messageID,
|
|
2025
|
-
goalId: 'goal-1',
|
|
2026
|
-
generation: 0,
|
|
2027
|
-
turnsUsed: 1,
|
|
2028
|
-
phase: 'reserved',
|
|
2029
|
-
text: fixedText,
|
|
2030
|
-
providerID: 'p',
|
|
2031
|
-
modelID: 'm',
|
|
2032
|
-
agent: 'build',
|
|
2033
|
-
});
|
|
2034
|
-
const goal = {
|
|
2035
|
-
...buildSession('active').metadata.yuri.goal,
|
|
2036
|
-
executionGeneration: 0,
|
|
2037
|
-
createdAt: 1,
|
|
2038
|
-
turnsUsed: 0,
|
|
2039
|
-
statusReason: 'resumed',
|
|
2040
|
-
pendingContinuation: pending,
|
|
2041
|
-
};
|
|
2042
|
-
await store.setSessionMetadata('ses-goal', { yuri: { goal } });
|
|
2043
|
-
const promptBodies = [];
|
|
2044
|
-
const knownMessageIDs = new Set();
|
|
2045
|
-
|
|
2046
|
-
await withFetch(makeOpenCodeFetch({ knownMessageIDs }), async () => {
|
|
2047
|
-
const originalFetch = globalThis.fetch;
|
|
2048
|
-
globalThis.fetch = async (input, init = {}) => {
|
|
2049
|
-
const reqPath = String(input).split('?')[0];
|
|
2050
|
-
if (pathEndsWith(reqPath, '/prompt') || pathEndsWith(reqPath, '/prompt_async')) {
|
|
2051
|
-
const body = JSON.parse(init.body || '{}');
|
|
2052
|
-
promptBodies.push(body);
|
|
2053
|
-
if (body.id) knownMessageIDs.add(body.id);
|
|
2054
|
-
return jsonResponse({
|
|
2055
|
-
data: { id: 'inbox_1', type: 'user', sessionID: 'ses-goal', time: { created: 1 }, payload: { text: 'x' }, delivery: 'steer' },
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
return originalFetch(input, init);
|
|
2059
|
-
};
|
|
2060
|
-
try {
|
|
2061
|
-
const runtime = createSessionGoalRuntime({
|
|
2062
|
-
buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
|
|
2063
|
-
getOpenCodeAuthHeaders: () => ({}),
|
|
2064
|
-
getSmallModelService: async () => ({
|
|
2065
|
-
generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"go"}' }),
|
|
2066
|
-
}),
|
|
2067
|
-
idleQuietMs: 1_000_000,
|
|
2068
|
-
kickoffQuietMs: 1,
|
|
2069
|
-
readSessionMetadata: (id) => store.get(id),
|
|
2070
|
-
mutateSessionMetadata: (id, decide) => store.mutateSessionMetadata(id, decide),
|
|
2071
|
-
});
|
|
2072
|
-
await runtime.runTick('ses-goal', '/repo');
|
|
2073
|
-
expect(promptBodies.length).toBe(1);
|
|
2074
|
-
expect(promptBodies[0].id).toBe(messageID);
|
|
2075
|
-
expect(promptBodies[0].text).toBe(fixedText);
|
|
2076
|
-
const finalMeta = await store.get('ses-goal');
|
|
2077
|
-
expect(finalMeta.yuri.goal.turnsUsed).toBe(1);
|
|
2078
|
-
expect(finalMeta.yuri.goal.pendingContinuation == null).toBe(true);
|
|
2079
|
-
runtime.stop();
|
|
2080
|
-
} finally {
|
|
2081
|
-
globalThis.fetch = originalFetch;
|
|
2082
|
-
cleanup();
|
|
2083
|
-
}
|
|
2084
|
-
});
|
|
2085
|
-
});
|
|
2086
|
-
|
|
2087
|
-
it('pending mutate is invisible to readers until persist succeeds', async () => {
|
|
2088
|
-
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-goal-pending-'));
|
|
2089
|
-
let unlock;
|
|
2090
|
-
const gate = new Promise((resolve) => { unlock = resolve; });
|
|
2091
|
-
const fsPromises = {
|
|
2092
|
-
...fs.promises,
|
|
2093
|
-
writeFile: async (target, payload, encoding) => {
|
|
2094
|
-
await gate;
|
|
2095
|
-
return fs.promises.writeFile(target, payload, encoding);
|
|
2096
|
-
},
|
|
2097
|
-
};
|
|
2098
|
-
const store = createSessionMetadataStore({ dataDir, fsPromises });
|
|
2099
|
-
// First write without gate
|
|
2100
|
-
const warm = createSessionMetadataStore({ dataDir });
|
|
2101
|
-
await warm.setSessionMetadata('ses-goal', {
|
|
2102
|
-
yuri: {
|
|
2103
|
-
goal: {
|
|
2104
|
-
...buildSession('active').metadata.yuri.goal,
|
|
2105
|
-
executionGeneration: 0,
|
|
2106
|
-
},
|
|
2107
|
-
},
|
|
2108
|
-
});
|
|
2109
|
-
await store.load();
|
|
2110
|
-
|
|
2111
|
-
const pending = store.mutateSessionMetadata('ses-goal', () => ({
|
|
2112
|
-
ok: true,
|
|
2113
|
-
patch: { yuri: { goal: { status: 'paused', executionGeneration: 1 } } },
|
|
2114
|
-
}));
|
|
2115
|
-
await expect(store.get('ses-goal')).resolves.toMatchObject({
|
|
2116
|
-
yuri: { goal: { status: 'active', executionGeneration: 0 } },
|
|
2117
|
-
});
|
|
2118
|
-
unlock();
|
|
2119
|
-
await pending;
|
|
2120
|
-
await expect(store.get('ses-goal')).resolves.toMatchObject({
|
|
2121
|
-
yuri: { goal: { status: 'paused', executionGeneration: 1 } },
|
|
2122
|
-
});
|
|
2123
|
-
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
2124
|
-
});
|
|
2125
|
-
});
|