kimaki 0.26.0 → 0.27.0
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/agent-model.e2e.test.js +25 -122
- package/dist/anthropic-account-identity.js +1 -0
- package/dist/anthropic-auth-plugin.js +1 -0
- package/dist/anthropic-auth-state.js +1 -0
- package/dist/bin.js +73 -19
- package/dist/cli-commands/maintenance.js +46 -7
- package/dist/cli-commands/send.js +24 -0
- package/dist/cli-commands/session.js +183 -8
- package/dist/cli-commands/task.js +13 -1
- package/dist/cli-parsing.test.js +59 -3
- package/dist/cli-runner.js +28 -4
- package/dist/cli-runner.test.js +27 -0
- package/dist/cli-send-thread.e2e.test.js +1 -1
- package/dist/cli.js +32 -0
- package/dist/commands/abort.js +5 -1
- package/dist/commands/agent.js +6 -8
- package/dist/commands/ask-question.js +21 -32
- package/dist/commands/ask-question.test.js +43 -1
- package/dist/commands/login.js +6 -0
- package/dist/commands/merge-worktree.js +36 -10
- package/dist/commands/model-variant.js +7 -1
- package/dist/commands/model.js +14 -8
- package/dist/commands/multioauth.js +1 -0
- package/dist/commands/new-worktree.js +170 -102
- package/dist/commands/user-command.js +6 -8
- package/dist/commands/worktrees.js +5 -13
- package/dist/config.js +16 -1
- package/dist/database.js +124 -3
- package/dist/db.js +22 -0
- package/dist/db.test.js +167 -1
- package/dist/discord-bot.js +34 -32
- package/dist/discord-command-registration.js +9 -1
- package/dist/discord-utils.js +13 -5
- package/dist/discord-utils.test.js +17 -1
- package/dist/errors.js +5 -0
- package/dist/exec-async.js +17 -5
- package/dist/external-directory-permissions.e2e.test.js +2 -2
- package/dist/file-edit-log.js +197 -0
- package/dist/file-edit-log.test.js +258 -0
- package/dist/format-tables.js +52 -0
- package/dist/format-tables.test.js +93 -0
- package/dist/gateway-proxy-reconnect.e2e.test.js +28 -8
- package/dist/gateway-proxy.e2e.test.js +5 -5
- package/dist/git-worktree-core.js +182 -17
- package/dist/ipc-tools-plugin.js +63 -3
- package/dist/kimaki-opencode-plugin-loading.e2e.test.js +122 -58
- package/dist/kimaki-opencode-plugin.js +7 -3
- package/dist/kimaki-workspace-adaptor.js +33 -10
- package/dist/logger.js +10 -1
- package/dist/markdown.js +3 -1
- package/dist/markdown.test.js +11 -3
- package/dist/message-formatting.js +18 -7
- package/dist/message-formatting.test.js +56 -9
- package/dist/oauth-rotation-shared.js +10 -0
- package/dist/openai-auth-plugin.js +1 -0
- package/dist/openai-auth-state.js +1 -0
- package/dist/opencode-command.test.js +60 -0
- package/dist/opencode.js +53 -12
- package/dist/question-abort-clears-dropdown.e2e.test.js +89 -0
- package/dist/question-text-before-dropdown.e2e.test.js +52 -0
- package/dist/queue-advanced-abort.e2e.test.js +1 -1
- package/dist/queue-advanced-action-buttons.e2e.test.js +3 -3
- package/dist/queue-advanced-e2e-setup.js +78 -5
- package/dist/queue-advanced-footer.e2e.test.js +40 -246
- package/dist/queue-advanced-model-switch.e2e.test.js +2 -2
- package/dist/queue-advanced-permissions-typing.e2e.test.js +7 -9
- package/dist/queue-advanced-question.e2e.test.js +31 -26
- package/dist/queue-advanced-typing-interrupt.e2e.test.js +2 -2
- package/dist/queue-delete-message.e2e.test.js +1 -1
- package/dist/queue-drain-after-interactive-ui.e2e.test.js +2 -2
- package/dist/queue-interrupt-drain.e2e.test.js +112 -2
- package/dist/queue-question-select-drain.e2e.test.js +30 -128
- package/dist/runtime-lifecycle.e2e.test.js +10 -37
- package/dist/schema.js +34 -0
- package/dist/session-handler/event-stream-state.js +267 -50
- package/dist/session-handler/event-stream-state.test.js +415 -8
- package/dist/session-handler/model-utils.js +159 -5
- package/dist/session-handler/model-utils.test.js +345 -0
- package/dist/session-handler/thread-session-runtime.js +252 -182
- package/dist/session-sleep.test.js +224 -0
- package/dist/session-title-rename.test.js +7 -39
- package/dist/sleep.e2e.test.js +491 -0
- package/dist/startup-time.e2e.test.js +2 -1
- package/dist/store.js +3 -0
- package/dist/system-message.js +59 -6
- package/dist/system-message.test.js +76 -6
- package/dist/task-runner.js +94 -4
- package/dist/task-schedule.js +56 -0
- package/dist/task-schedule.test.js +71 -1
- package/dist/thread-message-queue.e2e.test.js +10 -169
- package/dist/undo-redo.e2e.test.js +2 -2
- package/dist/voice-attachment.js +23 -1
- package/dist/voice-message.e2e.test.js +10 -10
- package/dist/voice.test.js +55 -29
- package/dist/worktree-clone-isolation.e2e.test.js +188 -0
- package/dist/worktree-lifecycle.e2e.test.js +29 -10
- package/dist/worktrees.js +226 -443
- package/dist/worktrees.test.js +435 -58
- package/dist/xai-auth-plugin.js +1 -0
- package/dist/xai-auth-state.js +1 -0
- package/package.json +8 -6
- package/skills/errore/SKILL.md +18 -0
- package/skills/goke/SKILL.md +150 -10
- package/skills/holocron/SKILL.md +37 -0
- package/skills/npm-package/SKILL.md +55 -35
- package/skills/profano/SKILL.md +17 -2
- package/skills/spiceflow/SKILL.md +39 -3
- package/skills/strada/SKILL.md +39 -0
- package/skills/zele/SKILL.md +19 -0
- package/src/agent-model.e2e.test.ts +25 -151
- package/src/anthropic-account-identity.ts +1 -0
- package/src/anthropic-auth-plugin.ts +1 -0
- package/src/anthropic-auth-state.ts +1 -0
- package/src/bin.ts +78 -26
- package/src/cli-commands/maintenance.ts +59 -13
- package/src/cli-commands/send.ts +25 -0
- package/src/cli-commands/session.ts +203 -9
- package/src/cli-commands/task.ts +13 -1
- package/src/cli-parsing.test.ts +69 -3
- package/src/cli-runner.test.ts +49 -0
- package/src/cli-runner.ts +28 -4
- package/src/cli-send-thread.e2e.test.ts +1 -1
- package/src/cli.ts +53 -0
- package/src/commands/abort.ts +6 -1
- package/src/commands/agent.ts +6 -6
- package/src/commands/ask-question.test.ts +48 -1
- package/src/commands/ask-question.ts +21 -32
- package/src/commands/login.ts +6 -0
- package/src/commands/merge-worktree.ts +43 -12
- package/src/commands/model-variant.ts +8 -1
- package/src/commands/model.ts +18 -8
- package/src/commands/multioauth.ts +1 -0
- package/src/commands/new-worktree.ts +138 -55
- package/src/commands/user-command.ts +6 -6
- package/src/commands/worktrees.ts +5 -12
- package/src/config.ts +18 -1
- package/src/database.ts +195 -3
- package/src/db.test.ts +188 -0
- package/src/db.ts +26 -0
- package/src/discord-bot.ts +35 -29
- package/src/discord-command-registration.ts +15 -1
- package/src/discord-utils.test.ts +19 -0
- package/src/discord-utils.ts +21 -6
- package/src/errors.ts +5 -0
- package/src/exec-async.ts +20 -11
- package/src/external-directory-permissions.e2e.test.ts +2 -2
- package/src/file-edit-log.test.ts +287 -0
- package/src/file-edit-log.ts +283 -0
- package/src/format-tables.test.ts +101 -0
- package/src/format-tables.ts +75 -0
- package/src/gateway-proxy-reconnect.e2e.test.ts +38 -8
- package/src/gateway-proxy.e2e.test.ts +5 -5
- package/src/git-worktree-core.ts +247 -20
- package/src/ipc-tools-plugin.ts +75 -5
- package/src/kimaki-opencode-plugin-loading.e2e.test.ts +188 -97
- package/src/kimaki-opencode-plugin.ts +7 -3
- package/src/kimaki-workspace-adaptor.ts +40 -11
- package/src/logger.ts +13 -4
- package/src/markdown.test.ts +13 -3
- package/src/markdown.ts +4 -1
- package/src/message-formatting.test.ts +86 -12
- package/src/message-formatting.ts +19 -7
- package/src/oauth-rotation-shared.ts +10 -0
- package/src/openai-auth-plugin.ts +1 -0
- package/src/openai-auth-state.ts +1 -0
- package/src/opencode-command.test.ts +81 -0
- package/src/opencode.ts +71 -11
- package/src/question-abort-clears-dropdown.e2e.test.ts +109 -0
- package/src/question-text-before-dropdown.e2e.test.ts +67 -0
- package/src/queue-advanced-abort.e2e.test.ts +1 -1
- package/src/queue-advanced-action-buttons.e2e.test.ts +3 -3
- package/src/queue-advanced-e2e-setup.ts +83 -4
- package/src/queue-advanced-footer.e2e.test.ts +47 -294
- package/src/queue-advanced-model-switch.e2e.test.ts +2 -2
- package/src/queue-advanced-permissions-typing.e2e.test.ts +7 -9
- package/src/queue-advanced-question.e2e.test.ts +35 -29
- package/src/queue-advanced-typing-interrupt.e2e.test.ts +2 -2
- package/src/queue-delete-message.e2e.test.ts +1 -1
- package/src/queue-drain-after-interactive-ui.e2e.test.ts +2 -2
- package/src/queue-interrupt-drain.e2e.test.ts +123 -2
- package/src/queue-question-select-drain.e2e.test.ts +32 -157
- package/src/runtime-lifecycle.e2e.test.ts +10 -41
- package/src/schema.sql +14 -1
- package/src/schema.ts +36 -0
- package/src/session-handler/event-stream-state.test.ts +437 -7
- package/src/session-handler/event-stream-state.ts +389 -53
- package/src/session-handler/model-utils.test.ts +415 -0
- package/src/session-handler/model-utils.ts +249 -5
- package/src/session-handler/thread-session-runtime.ts +300 -215
- package/src/session-sleep.test.ts +294 -0
- package/src/session-title-rename.test.ts +9 -48
- package/src/sleep.e2e.test.ts +562 -0
- package/src/startup-time.e2e.test.ts +5 -1
- package/src/store.ts +21 -0
- package/src/system-message.test.ts +86 -6
- package/src/system-message.ts +66 -7
- package/src/task-runner.ts +136 -2
- package/src/task-schedule.test.ts +76 -0
- package/src/task-schedule.ts +95 -0
- package/src/thread-message-queue.e2e.test.ts +10 -202
- package/src/undo-redo.e2e.test.ts +2 -2
- package/src/voice-attachment.ts +29 -1
- package/src/voice-message.e2e.test.ts +10 -10
- package/src/voice.test.ts +63 -29
- package/src/worktree-clone-isolation.e2e.test.ts +213 -0
- package/src/worktree-lifecycle.e2e.test.ts +29 -9
- package/src/worktrees.test.ts +505 -64
- package/src/worktrees.ts +257 -603
- package/src/xai-auth-plugin.ts +1 -0
- package/src/xai-auth-state.ts +1 -0
- package/dist/message-finish-field.e2e.test.js +0 -169
- package/dist/subagent-rate-limit-plugin.js +0 -184
- package/src/message-finish-field.e2e.test.ts +0 -196
- package/src/subagent-rate-limit-plugin.ts +0 -228
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Verifies OpenCode workspace creation stays bound to the requested local clone.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterAll, beforeAll, expect, test } from 'vitest';
|
|
5
|
+
import { setDataDir } from './config.js';
|
|
6
|
+
import { tryWorkspaceCreate } from './commands/new-worktree.js';
|
|
7
|
+
import { initializeOpencodeForDirectory, stopOpencodeServer } from './opencode.js';
|
|
8
|
+
import { chooseLockPort } from './test-utils.js';
|
|
9
|
+
import { execAsync, getManagedWorktreeDirectory } from './worktrees.js';
|
|
10
|
+
import { KIMAKI_WORKTREE_ADAPTER_TYPE } from './git-worktree-core.js';
|
|
11
|
+
const WORKTREE_BRANCH = 'opencode/kimaki-clone-isolation';
|
|
12
|
+
const REJECTED_WORKTREE_BRANCH = 'opencode/kimaki-rejected-clone-isolation';
|
|
13
|
+
async function git({ cwd, args }) {
|
|
14
|
+
const result = await execAsync(`git ${args.map((arg) => JSON.stringify(arg)).join(' ')}`, {
|
|
15
|
+
cwd,
|
|
16
|
+
timeout: 60_000,
|
|
17
|
+
});
|
|
18
|
+
return result.stdout.trim();
|
|
19
|
+
}
|
|
20
|
+
let sandbox = '';
|
|
21
|
+
let requestedClone = '';
|
|
22
|
+
let otherClone = '';
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
const root = path.resolve(process.cwd(), 'tmp');
|
|
25
|
+
fs.mkdirSync(root, { recursive: true });
|
|
26
|
+
sandbox = fs.mkdtempSync(path.join(root, 'worktree-clone-isolation-'));
|
|
27
|
+
const remote = path.join(sandbox, 'remote.git');
|
|
28
|
+
requestedClone = path.join(sandbox, 'holocron');
|
|
29
|
+
otherClone = path.join(sandbox, 'fumabase');
|
|
30
|
+
process.env['KIMAKI_LOCK_PORT'] = String(chooseLockPort({ key: 'worktree-clone-isolation' }));
|
|
31
|
+
setDataDir(path.join(sandbox, 'data'));
|
|
32
|
+
await git({ cwd: sandbox, args: ['init', '--bare', '-b', 'main', remote] });
|
|
33
|
+
await git({ cwd: sandbox, args: ['clone', remote, otherClone] });
|
|
34
|
+
await git({
|
|
35
|
+
cwd: otherClone,
|
|
36
|
+
args: ['config', 'user.email', 'kimaki-tests@example.com'],
|
|
37
|
+
});
|
|
38
|
+
await git({ cwd: otherClone, args: ['config', 'user.name', 'Kimaki Tests'] });
|
|
39
|
+
fs.writeFileSync(path.join(otherClone, 'preview.txt'), 'old preview\n');
|
|
40
|
+
await git({ cwd: otherClone, args: ['add', 'preview.txt'] });
|
|
41
|
+
await git({ cwd: otherClone, args: ['commit', '-m', 'old preview'] });
|
|
42
|
+
await git({ cwd: otherClone, args: ['push', 'origin', 'HEAD:main'] });
|
|
43
|
+
await git({ cwd: otherClone, args: ['switch', '-c', 'preview'] });
|
|
44
|
+
await git({ cwd: sandbox, args: ['clone', remote, requestedClone] });
|
|
45
|
+
await git({
|
|
46
|
+
cwd: requestedClone,
|
|
47
|
+
args: ['config', 'user.email', 'kimaki-tests@example.com'],
|
|
48
|
+
});
|
|
49
|
+
await git({ cwd: requestedClone, args: ['config', 'user.name', 'Kimaki Tests'] });
|
|
50
|
+
fs.mkdirSync(path.join(requestedClone, 'vite'));
|
|
51
|
+
fs.writeFileSync(path.join(requestedClone, 'vite', 'README.md'), 'new layout\n');
|
|
52
|
+
await git({ cwd: requestedClone, args: ['add', 'vite/README.md'] });
|
|
53
|
+
await git({ cwd: requestedClone, args: ['commit', '-m', 'add vite layout'] });
|
|
54
|
+
}, 20_000);
|
|
55
|
+
afterAll(async () => {
|
|
56
|
+
await stopOpencodeServer();
|
|
57
|
+
delete process.env['KIMAKI_LOCK_PORT'];
|
|
58
|
+
if (sandbox)
|
|
59
|
+
fs.rmSync(sandbox, { recursive: true, force: true });
|
|
60
|
+
});
|
|
61
|
+
test('creates a workspace from the exact requested clone and commit', async () => {
|
|
62
|
+
const requestedCommit = await git({
|
|
63
|
+
cwd: requestedClone,
|
|
64
|
+
args: ['rev-parse', 'HEAD^{commit}'],
|
|
65
|
+
});
|
|
66
|
+
const requestedCommonDirectory = path.resolve(requestedClone, await git({
|
|
67
|
+
cwd: requestedClone,
|
|
68
|
+
args: ['rev-parse', '--git-common-dir'],
|
|
69
|
+
}));
|
|
70
|
+
const requestedClientResult = await initializeOpencodeForDirectory(requestedClone);
|
|
71
|
+
if (requestedClientResult instanceof Error)
|
|
72
|
+
throw requestedClientResult;
|
|
73
|
+
const otherClientResult = await initializeOpencodeForDirectory(otherClone);
|
|
74
|
+
if (otherClientResult instanceof Error)
|
|
75
|
+
throw otherClientResult;
|
|
76
|
+
const requestedClient = requestedClientResult();
|
|
77
|
+
const otherClient = otherClientResult();
|
|
78
|
+
// Load the requested clone first, then overwrite the colliding OpenCode
|
|
79
|
+
// project adapter with the other clone before creating the workspace.
|
|
80
|
+
await requestedClient.config.get({ directory: requestedClone });
|
|
81
|
+
await otherClient.config.get({ directory: otherClone });
|
|
82
|
+
const response = await requestedClient.experimental.workspace.create({
|
|
83
|
+
directory: requestedClone,
|
|
84
|
+
type: KIMAKI_WORKTREE_ADAPTER_TYPE,
|
|
85
|
+
branch: WORKTREE_BRANCH,
|
|
86
|
+
extra: {
|
|
87
|
+
projectDirectory: requestedClone,
|
|
88
|
+
baseCommit: requestedCommit,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
if (response.error)
|
|
92
|
+
throw new Error(JSON.stringify(response.error));
|
|
93
|
+
const workspace = response.data;
|
|
94
|
+
if (!workspace)
|
|
95
|
+
throw new Error('OpenCode returned no workspace');
|
|
96
|
+
try {
|
|
97
|
+
const actualCommit = await git({
|
|
98
|
+
cwd: workspace.directory,
|
|
99
|
+
args: ['rev-parse', 'HEAD^{commit}'],
|
|
100
|
+
});
|
|
101
|
+
const actualCommonDirectory = path.resolve(workspace.directory, await git({
|
|
102
|
+
cwd: workspace.directory,
|
|
103
|
+
args: ['rev-parse', '--git-common-dir'],
|
|
104
|
+
}));
|
|
105
|
+
expect({
|
|
106
|
+
usesRequestedClone: path.resolve(actualCommonDirectory) === path.resolve(requestedCommonDirectory),
|
|
107
|
+
usesRequestedCommit: actualCommit === requestedCommit,
|
|
108
|
+
hasRequestedLayout: fs.existsSync(path.join(workspace.directory, 'vite', 'README.md')),
|
|
109
|
+
absentFromOtherClone: !(await git({
|
|
110
|
+
cwd: otherClone,
|
|
111
|
+
args: ['worktree', 'list', '--porcelain'],
|
|
112
|
+
})).includes(workspace.directory),
|
|
113
|
+
}).toMatchInlineSnapshot(`
|
|
114
|
+
{
|
|
115
|
+
"absentFromOtherClone": true,
|
|
116
|
+
"hasRequestedLayout": true,
|
|
117
|
+
"usesRequestedClone": true,
|
|
118
|
+
"usesRequestedCommit": true,
|
|
119
|
+
}
|
|
120
|
+
`);
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
await requestedClient.experimental.workspace.remove({
|
|
124
|
+
id: workspace.id,
|
|
125
|
+
directory: requestedClone,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}, 30_000);
|
|
129
|
+
test('removes workspace state when identity validation rejects creation', async () => {
|
|
130
|
+
const requestedCommit = await git({
|
|
131
|
+
cwd: requestedClone,
|
|
132
|
+
args: ['rev-parse', 'HEAD^{commit}'],
|
|
133
|
+
});
|
|
134
|
+
const result = await tryWorkspaceCreate({
|
|
135
|
+
worktreeName: REJECTED_WORKTREE_BRANCH,
|
|
136
|
+
projectDirectory: requestedClone,
|
|
137
|
+
baseCommit: requestedCommit.toUpperCase(),
|
|
138
|
+
});
|
|
139
|
+
expect(result).toBeInstanceOf(Error);
|
|
140
|
+
const clientResult = await initializeOpencodeForDirectory(requestedClone);
|
|
141
|
+
if (clientResult instanceof Error)
|
|
142
|
+
throw clientResult;
|
|
143
|
+
const client = clientResult();
|
|
144
|
+
const listResponse = await client.experimental.workspace.list({
|
|
145
|
+
directory: requestedClone,
|
|
146
|
+
});
|
|
147
|
+
if (listResponse.error)
|
|
148
|
+
throw new Error(JSON.stringify(listResponse.error));
|
|
149
|
+
const rejectedWorkspaces = (listResponse.data ?? []).filter((workspace) => {
|
|
150
|
+
return workspace.branch === REJECTED_WORKTREE_BRANCH;
|
|
151
|
+
});
|
|
152
|
+
try {
|
|
153
|
+
const managedDirectory = getManagedWorktreeDirectory({
|
|
154
|
+
directory: requestedClone,
|
|
155
|
+
name: REJECTED_WORKTREE_BRANCH,
|
|
156
|
+
});
|
|
157
|
+
const [requestedWorktrees, otherWorktrees] = await Promise.all([
|
|
158
|
+
git({ cwd: requestedClone, args: ['worktree', 'list', '--porcelain'] }),
|
|
159
|
+
git({ cwd: otherClone, args: ['worktree', 'list', '--porcelain'] }),
|
|
160
|
+
]);
|
|
161
|
+
const branchExists = await execAsync(`git show-ref --verify --quiet ${JSON.stringify(`refs/heads/${REJECTED_WORKTREE_BRANCH}`)}`, { cwd: requestedClone })
|
|
162
|
+
.then(() => true)
|
|
163
|
+
.catch(() => false);
|
|
164
|
+
expect({
|
|
165
|
+
workspaceRows: rejectedWorkspaces.length,
|
|
166
|
+
directoryExists: fs.existsSync(managedDirectory),
|
|
167
|
+
requestedCloneRegistration: requestedWorktrees.includes(managedDirectory),
|
|
168
|
+
otherCloneRegistration: otherWorktrees.includes(managedDirectory),
|
|
169
|
+
branchExists,
|
|
170
|
+
}).toMatchInlineSnapshot(`
|
|
171
|
+
{
|
|
172
|
+
"branchExists": false,
|
|
173
|
+
"directoryExists": false,
|
|
174
|
+
"otherCloneRegistration": false,
|
|
175
|
+
"requestedCloneRegistration": false,
|
|
176
|
+
"workspaceRows": 0,
|
|
177
|
+
}
|
|
178
|
+
`);
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
await Promise.all(rejectedWorkspaces.map((workspace) => {
|
|
182
|
+
return client.experimental.workspace.remove({
|
|
183
|
+
id: workspace.id,
|
|
184
|
+
directory: requestedClone,
|
|
185
|
+
});
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
}, 30_000);
|
|
@@ -17,7 +17,7 @@ import { setDataDir } from './config.js';
|
|
|
17
17
|
import { store } from './store.js';
|
|
18
18
|
import { startDiscordBot } from './discord-bot.js';
|
|
19
19
|
import { getRuntime } from './session-handler/thread-session-runtime.js';
|
|
20
|
-
import { setBotToken, initDatabase, closeDatabase, setChannelDirectory, setChannelVerbosity, setChannelWorktreesEnabled, getThreadSession, getThreadWorktreeOrWorkspace, } from './database.js';
|
|
20
|
+
import { setBotToken, initDatabase, closeDatabase, setChannelDirectory, setChannelVerbosity, setChannelWorktreesEnabled, getThreadSession, getThreadWorktreeOrWorkspace, getSessionModel, setSessionModel, } from './database.js';
|
|
21
21
|
import { startHranaServer, stopHranaServer } from './hrana-server.js';
|
|
22
22
|
import { initializeOpencodeForDirectory, stopOpencodeServer, } from './opencode.js';
|
|
23
23
|
import { chooseLockPort, cleanupTestSessions, waitForBotMessageContaining, } from './test-utils.js';
|
|
@@ -31,6 +31,7 @@ const WORKTREE_SUFFIX = Date.now().toString(36).slice(-6);
|
|
|
31
31
|
const WORKTREE_NAME = `wt-e2e-${WORKTREE_SUFFIX}`;
|
|
32
32
|
const CHANNEL_WORKTREE_NAME = `wt-chan-${WORKTREE_SUFFIX}`;
|
|
33
33
|
const AUTO_WORKTREE_SUFFIX = `wt-auto-${WORKTREE_SUFFIX}`;
|
|
34
|
+
const SOURCE_MODEL = 'source-model-v2';
|
|
34
35
|
function normalizeWorktreeLifecycleText(text) {
|
|
35
36
|
return text
|
|
36
37
|
.replaceAll(CHANNEL_WORKTREE_NAME, 'CHANNEL_WORKTREE_NAME')
|
|
@@ -172,6 +173,10 @@ describe('worktree lifecycle', () => {
|
|
|
172
173
|
matchers: createDeterministicMatchers(),
|
|
173
174
|
},
|
|
174
175
|
});
|
|
176
|
+
const providerConfig = opencodeConfig.provider['deterministic-provider'];
|
|
177
|
+
if (!providerConfig)
|
|
178
|
+
throw new Error('Missing deterministic provider config');
|
|
179
|
+
providerConfig.models[SOURCE_MODEL] = { name: SOURCE_MODEL };
|
|
175
180
|
fs.writeFileSync(path.join(directories.projectDirectory, 'opencode.json'), JSON.stringify(opencodeConfig, null, 2));
|
|
176
181
|
fs.writeFileSync(path.join(directories.nonGitDirectory, 'opencode.json'), JSON.stringify(opencodeConfig, null, 2));
|
|
177
182
|
// Initialize git repo after writing opencode.json so the initial commit
|
|
@@ -306,6 +311,12 @@ describe('worktree lifecycle', () => {
|
|
|
306
311
|
expect(runtimeBefore.sdkDirectory).toBe(directories.projectDirectory);
|
|
307
312
|
const sessionBefore = await getThreadSession(thread.id);
|
|
308
313
|
expect(sessionBefore).toBeTruthy();
|
|
314
|
+
if (!sessionBefore)
|
|
315
|
+
throw new Error('Source session was not persisted');
|
|
316
|
+
await setSessionModel({
|
|
317
|
+
sessionId: sessionBefore,
|
|
318
|
+
modelId: `deterministic-provider/${SOURCE_MODEL}`,
|
|
319
|
+
});
|
|
309
320
|
// 2. Run /new-worktree inside the source thread.
|
|
310
321
|
// This should create a new worktree thread instead of switching this one.
|
|
311
322
|
const { id: interactionId } = await th
|
|
@@ -340,6 +351,11 @@ describe('worktree lifecycle', () => {
|
|
|
340
351
|
text: 'Branch:',
|
|
341
352
|
timeout: 10_000,
|
|
342
353
|
});
|
|
354
|
+
// Messages sent as soon as the checkout is ready must wait for the
|
|
355
|
+
// source session fork and keep its model.
|
|
356
|
+
await worktreeTh.user(TEST_USER_ID).sendMessage({
|
|
357
|
+
content: 'Reply with exactly: after-worktree-thread',
|
|
358
|
+
});
|
|
343
359
|
await waitForBotMessageContaining({
|
|
344
360
|
discord,
|
|
345
361
|
threadId: worktreeThread.id,
|
|
@@ -354,6 +370,12 @@ describe('worktree lifecycle', () => {
|
|
|
354
370
|
if (!worktreeSession)
|
|
355
371
|
throw new Error('Worktree session was not persisted');
|
|
356
372
|
expect(worktreeSession).not.toBe(sessionBefore);
|
|
373
|
+
await expect(getSessionModel(worktreeSession)).resolves.toMatchInlineSnapshot(`
|
|
374
|
+
{
|
|
375
|
+
"modelId": "deterministic-provider/source-model-v2",
|
|
376
|
+
"variant": null,
|
|
377
|
+
}
|
|
378
|
+
`);
|
|
357
379
|
await expect(getThreadWorktreeOrWorkspace(thread.id)).resolves.toBeUndefined();
|
|
358
380
|
const worktreeInfo = await getThreadWorktreeOrWorkspace(worktreeThread.id);
|
|
359
381
|
expect(worktreeInfo?.status).toBe('ready');
|
|
@@ -378,9 +400,6 @@ describe('worktree lifecycle', () => {
|
|
|
378
400
|
expect(worktreeRuntime.sdkDirectory).toContain(`${path.sep}worktrees${path.sep}`);
|
|
379
401
|
// 4. Send messages to both threads. The source continues in the base
|
|
380
402
|
// checkout, and the new thread runs in the worktree checkout.
|
|
381
|
-
await worktreeTh.user(TEST_USER_ID).sendMessage({
|
|
382
|
-
content: 'Reply with exactly: after-worktree-thread',
|
|
383
|
-
});
|
|
384
403
|
await th.user(TEST_USER_ID).sendMessage({
|
|
385
404
|
content: 'Reply with exactly: after-source-thread',
|
|
386
405
|
});
|
|
@@ -405,7 +424,7 @@ describe('worktree lifecycle', () => {
|
|
|
405
424
|
discord,
|
|
406
425
|
threadId: worktreeThread.id,
|
|
407
426
|
userId: TEST_USER_ID,
|
|
408
|
-
text:
|
|
427
|
+
text: SOURCE_MODEL,
|
|
409
428
|
afterUserMessageIncludes: 'after-worktree-thread',
|
|
410
429
|
timeout: 4_000,
|
|
411
430
|
});
|
|
@@ -413,7 +432,7 @@ describe('worktree lifecycle', () => {
|
|
|
413
432
|
discord,
|
|
414
433
|
threadId: thread.id,
|
|
415
434
|
userId: TEST_USER_ID,
|
|
416
|
-
text:
|
|
435
|
+
text: SOURCE_MODEL,
|
|
417
436
|
afterUserMessageIncludes: 'after-source-thread',
|
|
418
437
|
timeout: 4_000,
|
|
419
438
|
});
|
|
@@ -425,12 +444,12 @@ describe('worktree lifecycle', () => {
|
|
|
425
444
|
*using deterministic-provider/deterministic-v2*
|
|
426
445
|
⬥ ok
|
|
427
446
|
Creating worktree in <#THREAD_ID>
|
|
428
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
447
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000901>
|
|
429
448
|
--- from: user (worktree-tester)
|
|
430
449
|
Reply with exactly: after-source-thread
|
|
431
450
|
--- from: assistant (TestBot)
|
|
432
451
|
⬥ ok
|
|
433
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅
|
|
452
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ source-model-v2* <@200000000000000901>"
|
|
434
453
|
`);
|
|
435
454
|
expect(sourceText).toContain('Reply with exactly: before-worktree');
|
|
436
455
|
expect(sourceText).toContain('Reply with exactly: after-source-thread');
|
|
@@ -447,7 +466,7 @@ describe('worktree lifecycle', () => {
|
|
|
447
466
|
Reply with exactly: after-worktree-thread
|
|
448
467
|
--- from: assistant (TestBot)
|
|
449
468
|
⬥ ok
|
|
450
|
-
*WORKTREE_NAME ⋅ opencode/kimaki-WORKTREE_NAME ⋅ Ns ⋅ N% ⋅
|
|
469
|
+
*WORKTREE_NAME ⋅ opencode/kimaki-WORKTREE_NAME ⋅ Ns ⋅ N% ⋅ source-model-v2* <@200000000000000901>"
|
|
451
470
|
`);
|
|
452
471
|
expect(worktreeText).toContain('Worktree:');
|
|
453
472
|
expect(worktreeText).toContain('Branch:');
|
|
@@ -637,7 +656,7 @@ describe('worktree lifecycle', () => {
|
|
|
637
656
|
--- from: user (worktree-tester)
|
|
638
657
|
Reply with exactly: non-git-second
|
|
639
658
|
--- from: assistant (TestBot)
|
|
640
|
-
*non-git-project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
659
|
+
*non-git-project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000901>
|
|
641
660
|
⬥ ok"
|
|
642
661
|
`);
|
|
643
662
|
expect(text).toContain('Reply with exactly: non-git-first');
|