dsh-cross-memory 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +247 -2
- package/cordis.patch.yml +27 -0
- package/docs/DETAIL.md +13 -0
- package/docs/DETAIL.zh.md +17 -0
- package/icon.svg +1 -0
- package/lib/backfill.js +273 -0
- package/lib/citations.js +305 -0
- package/lib/client.js +1550 -0
- package/lib/config.js +736 -0
- package/lib/consolidate.js +1119 -0
- package/lib/extract.js +570 -0
- package/lib/gate.js +137 -0
- package/lib/git-origin.js +224 -0
- package/lib/index.js +4475 -0
- package/lib/log.js +260 -0
- package/lib/loops.js +186 -0
- package/lib/notices.js +195 -0
- package/lib/notify.js +33 -0
- package/lib/persona.js +112 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +455 -0
- package/lib/render.js +678 -0
- package/lib/retention.js +64 -0
- package/lib/schedule.js +245 -0
- package/lib/search.js +1068 -0
- package/lib/skills.js +220 -0
- package/lib/state.js +701 -0
- package/lib/storage.js +1424 -0
- package/lib/sync-runtime.js +268 -0
- package/lib/sync.js +620 -0
- package/lib/test/activity.test.js +74 -0
- package/lib/test/archive.test.js +182 -0
- package/lib/test/backfill.test.js +144 -0
- package/lib/test/citations.test.js +91 -0
- package/lib/test/client-wiring.test.js +134 -0
- package/lib/test/consolidate-job.test.js +95 -0
- package/lib/test/consolidate.test.js +430 -0
- package/lib/test/consolidation-selection.test.js +152 -0
- package/lib/test/dedupe-keys.test.js +230 -0
- package/lib/test/delta.test.js +93 -0
- package/lib/test/derived.test.js +110 -0
- package/lib/test/disputes-panel.test.js +314 -0
- package/lib/test/eval.test.js +171 -0
- package/lib/test/expand.test.js +164 -0
- package/lib/test/extract.test.js +1020 -0
- package/lib/test/git-origin.test.js +189 -0
- package/lib/test/injection.test.js +440 -0
- package/lib/test/kind-filter.test.js +49 -0
- package/lib/test/legacy-state.test.js +69 -0
- package/lib/test/log.test.js +156 -0
- package/lib/test/loops.test.js +86 -0
- package/lib/test/memory.test.js +855 -0
- package/lib/test/notices.test.js +140 -0
- package/lib/test/persona.test.js +73 -0
- package/lib/test/prefilter.test.js +73 -0
- package/lib/test/preset.test.js +77 -0
- package/lib/test/raw-recall.test.js +186 -0
- package/lib/test/recall.test.js +433 -0
- package/lib/test/reflection.test.js +64 -0
- package/lib/test/remote.test.js +227 -0
- package/lib/test/retention.test.js +117 -0
- package/lib/test/retrieval.test.js +142 -0
- package/lib/test/rotation.test.js +228 -0
- package/lib/test/schedule.test.js +112 -0
- package/lib/test/settings-card.test.js +58 -0
- package/lib/test/skills.test.js +129 -0
- package/lib/test/state.test.js +212 -0
- package/lib/test/subagent-contract.test.js +139 -0
- package/lib/test/sweep.test.js +159 -0
- package/lib/test/sync.test.js +314 -0
- package/lib/test/time.test.js +171 -0
- package/lib/time.js +303 -0
- package/lib/tool.js +330 -0
- package/lib/types/backfill.d.ts +96 -0
- package/lib/types/citations.d.ts +105 -0
- package/lib/types/config.d.ts +811 -0
- package/lib/types/consolidate.d.ts +742 -0
- package/lib/types/extract.d.ts +352 -0
- package/lib/types/gate.d.ts +83 -0
- package/lib/types/git-origin.d.ts +23 -0
- package/lib/types/index.d.ts +1316 -0
- package/lib/types/log.d.ts +144 -0
- package/lib/types/loops.d.ts +82 -0
- package/lib/types/notices.d.ts +117 -0
- package/lib/types/notify.d.ts +12 -0
- package/lib/types/persona.d.ts +43 -0
- package/lib/types/query.d.ts +45 -0
- package/lib/types/raw-recall.d.ts +84 -0
- package/lib/types/reflection.d.ts +122 -0
- package/lib/types/remote.d.ts +233 -0
- package/lib/types/render.d.ts +286 -0
- package/lib/types/retention.d.ts +66 -0
- package/lib/types/schedule.d.ts +116 -0
- package/lib/types/search.d.ts +583 -0
- package/lib/types/skills.d.ts +71 -0
- package/lib/types/state.d.ts +294 -0
- package/lib/types/storage.d.ts +458 -0
- package/lib/types/sync-runtime.d.ts +103 -0
- package/lib/types/sync.d.ts +222 -0
- package/lib/types/test/activity.test.d.ts +1 -0
- package/lib/types/test/archive.test.d.ts +1 -0
- package/lib/types/test/backfill.test.d.ts +1 -0
- package/lib/types/test/citations.test.d.ts +1 -0
- package/lib/types/test/client-wiring.test.d.ts +1 -0
- package/lib/types/test/consolidate-job.test.d.ts +1 -0
- package/lib/types/test/consolidate.test.d.ts +1 -0
- package/lib/types/test/consolidation-selection.test.d.ts +1 -0
- package/lib/types/test/dedupe-keys.test.d.ts +1 -0
- package/lib/types/test/delta.test.d.ts +1 -0
- package/lib/types/test/derived.test.d.ts +1 -0
- package/lib/types/test/disputes-panel.test.d.ts +1 -0
- package/lib/types/test/eval.test.d.ts +1 -0
- package/lib/types/test/expand.test.d.ts +1 -0
- package/lib/types/test/extract.test.d.ts +1 -0
- package/lib/types/test/git-origin.test.d.ts +1 -0
- package/lib/types/test/injection.test.d.ts +1 -0
- package/lib/types/test/kind-filter.test.d.ts +1 -0
- package/lib/types/test/legacy-state.test.d.ts +1 -0
- package/lib/types/test/log.test.d.ts +1 -0
- package/lib/types/test/loops.test.d.ts +1 -0
- package/lib/types/test/memory.test.d.ts +1 -0
- package/lib/types/test/notices.test.d.ts +1 -0
- package/lib/types/test/persona.test.d.ts +1 -0
- package/lib/types/test/prefilter.test.d.ts +1 -0
- package/lib/types/test/preset.test.d.ts +1 -0
- package/lib/types/test/raw-recall.test.d.ts +1 -0
- package/lib/types/test/recall.test.d.ts +1 -0
- package/lib/types/test/reflection.test.d.ts +1 -0
- package/lib/types/test/remote.test.d.ts +1 -0
- package/lib/types/test/retention.test.d.ts +1 -0
- package/lib/types/test/retrieval.test.d.ts +1 -0
- package/lib/types/test/rotation.test.d.ts +1 -0
- package/lib/types/test/schedule.test.d.ts +1 -0
- package/lib/types/test/settings-card.test.d.ts +1 -0
- package/lib/types/test/skills.test.d.ts +1 -0
- package/lib/types/test/state.test.d.ts +1 -0
- package/lib/types/test/subagent-contract.test.d.ts +1 -0
- package/lib/types/test/sweep.test.d.ts +1 -0
- package/lib/types/test/sync.test.d.ts +1 -0
- package/lib/types/test/time.test.d.ts +1 -0
- package/lib/types/time.d.ts +67 -0
- package/lib/types/tool.d.ts +9 -0
- package/lib/types/types.d.ts +374 -0
- package/lib/types/workspace.d.ts +20 -0
- package/lib/types.js +47 -0
- package/lib/workspace.js +65 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotation-block tests for {@link MemoriesRuntime}.
|
|
3
|
+
*
|
|
4
|
+
* The summary can name only a dozen entries; the rest of a large store used to
|
|
5
|
+
* be invisible forever. The rotation block spends about a kilobyte on titles
|
|
6
|
+
* so each conversation surfaces a different slice, once, without repeating what
|
|
7
|
+
* the summary already listed.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-cross-memory/test/rotation.test
|
|
10
|
+
*/
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import test from 'node:test';
|
|
16
|
+
import { MemoriesRuntime } from '../index.js';
|
|
17
|
+
import { DEFAULT_ROTATION_ENTRIES } from '../config.js';
|
|
18
|
+
/** A context stand-in exposing only what the runtime touches. */
|
|
19
|
+
const stubContext = {
|
|
20
|
+
get: () => undefined,
|
|
21
|
+
logger: { info: () => undefined, warn: () => undefined, debug: () => undefined },
|
|
22
|
+
};
|
|
23
|
+
/** A session stand-in with an optional restored history. */
|
|
24
|
+
function stubSession(cwd, id = 'session-rotation', history = []) {
|
|
25
|
+
let seq = 1;
|
|
26
|
+
return {
|
|
27
|
+
id,
|
|
28
|
+
header: { version: 0, id, createdAt: 0, cwd, isSeeded: false },
|
|
29
|
+
get seq() { return seq += 1; },
|
|
30
|
+
requestHeader: () => undefined,
|
|
31
|
+
deriveMessages: () => [...history],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** An agent stand-in exposing only `session`. */
|
|
35
|
+
function stubAgent(session) {
|
|
36
|
+
return { id: session.id, session, status: 'idle' };
|
|
37
|
+
}
|
|
38
|
+
/** The model-visible text of one message. */
|
|
39
|
+
function textOf(message) {
|
|
40
|
+
const blocks = message.content;
|
|
41
|
+
return blocks.filter((block) => block.type === 'text').map((block) => block.text ?? '').join('\n');
|
|
42
|
+
}
|
|
43
|
+
/** Titles listed by a rotation block, in order. */
|
|
44
|
+
function titlesOf(text) {
|
|
45
|
+
return text.split('\n')
|
|
46
|
+
.filter((line) => line.startsWith('- '))
|
|
47
|
+
.map((line) => line.replace(/^- (?:\[project\] )?\[[a-z]+\] /u, '').trim());
|
|
48
|
+
}
|
|
49
|
+
/** Seed `count` distinct global memories. */
|
|
50
|
+
async function seed(runtime, session, count, prefix = 'memory') {
|
|
51
|
+
for (let index = 0; index < count; index += 1) {
|
|
52
|
+
await runtime.write(session, {
|
|
53
|
+
scope: 'global',
|
|
54
|
+
title: `${prefix} ${index}`,
|
|
55
|
+
body: `Body for ${prefix} ${index}; this body must never appear in the rotation block.`,
|
|
56
|
+
tags: [],
|
|
57
|
+
}, 'tool');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
test('the rotation block lists titles the summary had no room for, once', async (t) => {
|
|
61
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-'));
|
|
62
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false });
|
|
63
|
+
t.after(async () => {
|
|
64
|
+
runtime.dispose();
|
|
65
|
+
await rm(dir, { recursive: true, force: true });
|
|
66
|
+
});
|
|
67
|
+
const agent = stubAgent(stubSession(dir));
|
|
68
|
+
await seed(runtime, agent.session, 30);
|
|
69
|
+
const summary = await runtime.injectionFor(agent);
|
|
70
|
+
assert.ok(summary !== undefined);
|
|
71
|
+
const summaryText = textOf(summary);
|
|
72
|
+
const rotation = await runtime.rotationFor(agent);
|
|
73
|
+
assert.ok(rotation !== undefined, 'the summary left entries for the rotation block');
|
|
74
|
+
const rotationText = textOf(rotation);
|
|
75
|
+
assert.match(rotationText, /memory-index/u);
|
|
76
|
+
assert.ok(titlesOf(rotationText).length > 0, 'at least one title is listed');
|
|
77
|
+
// Titles only: bodies cost 3-4x and belong behind the memory tool.
|
|
78
|
+
assert.doesNotMatch(rotationText, /this body must never appear/u);
|
|
79
|
+
const listed = titlesOf(rotationText);
|
|
80
|
+
assert.ok(listed.length <= DEFAULT_ROTATION_ENTRIES, `at most the configured count (got ${listed.length})`);
|
|
81
|
+
const summaryTitles = new Set(summaryText.split('\n')
|
|
82
|
+
.filter((line) => line.startsWith('- '))
|
|
83
|
+
.map((line) => line.replace(/^- (?:📌 )?/u, '').replace(/ \(\d{4}-\d{2}-\d{2}.*$/u, '').trim()));
|
|
84
|
+
for (const title of listed) {
|
|
85
|
+
assert.ok(!summaryTitles.has(title), `the rotation block must not repeat ${title}, which the summary already listed`);
|
|
86
|
+
}
|
|
87
|
+
assert.equal(await runtime.rotationFor(agent), undefined, 'once per conversation');
|
|
88
|
+
t.after(() => runtime.dispose());
|
|
89
|
+
});
|
|
90
|
+
test('a later conversation rotates to different entries', async (t) => {
|
|
91
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot2-'));
|
|
92
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false });
|
|
93
|
+
t.after(() => runtime.dispose());
|
|
94
|
+
await seed(runtime, stubAgent(stubSession(dir)).session, 60);
|
|
95
|
+
const first = stubAgent(stubSession(dir, 'session-a'));
|
|
96
|
+
assert.ok(await runtime.injectionFor(first) !== undefined);
|
|
97
|
+
const firstRotation = await runtime.rotationFor(first);
|
|
98
|
+
assert.ok(firstRotation !== undefined);
|
|
99
|
+
const firstTitles = new Set(titlesOf(textOf(firstRotation)));
|
|
100
|
+
const second = stubAgent(stubSession(dir, 'session-b'));
|
|
101
|
+
assert.ok(await runtime.injectionFor(second) !== undefined);
|
|
102
|
+
const secondRotation = await runtime.rotationFor(second);
|
|
103
|
+
assert.ok(secondRotation !== undefined, '40 entries leave material for a second conversation');
|
|
104
|
+
const secondTitles = titlesOf(textOf(secondRotation));
|
|
105
|
+
assert.ok(secondTitles.length > 0);
|
|
106
|
+
for (const title of secondTitles) {
|
|
107
|
+
assert.ok(!firstTitles.has(title), `${title} was already rotated in the first conversation`);
|
|
108
|
+
}
|
|
109
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
110
|
+
});
|
|
111
|
+
test('the surfaced clock comes from state.db, not the entry mirror', async (t) => {
|
|
112
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-clock-'));
|
|
113
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false });
|
|
114
|
+
t.after(async () => {
|
|
115
|
+
runtime.dispose();
|
|
116
|
+
await rm(dir, { recursive: true, force: true });
|
|
117
|
+
});
|
|
118
|
+
const session = stubSession(dir, 'session-clock');
|
|
119
|
+
await runtime.write(session, { scope: 'global', title: 'mirror only', body: 'The mirror claims it was shown.', tags: [] }, 'tool');
|
|
120
|
+
// A stale mirror: the file says surfaced, the usage table has no row for it.
|
|
121
|
+
// This is the legacy shape measured on the real store (files claimed 85.8%
|
|
122
|
+
// surfaced while state.db had far fewer rows), so selection must not trust it.
|
|
123
|
+
const [stored] = await runtime.store.list('global', undefined, { fresh: true });
|
|
124
|
+
assert.ok(stored !== undefined);
|
|
125
|
+
await runtime.store.writeCounters(stored, undefined, { uses: 0, lastUsedAt: 0, surfacedAt: Date.now() });
|
|
126
|
+
const before = (await runtime.allScopes(stubSession(dir, 'session-clock')))[0]?.entries.find((entry) => entry.id === stored.id);
|
|
127
|
+
assert.equal(before?.lastSurfacedAt, 0, 'the state database is authoritative');
|
|
128
|
+
// A real surfacing writes a usage row, and from then on the entry counts as seen.
|
|
129
|
+
runtime.state.bumpSurfaced('global', stored.id);
|
|
130
|
+
const after = (await runtime.allScopes(stubSession(dir, 'session-clock')))[0]?.entries.find((entry) => entry.id === stored.id);
|
|
131
|
+
assert.ok((after?.lastSurfacedAt ?? 0) > 0, 'a usage row surfaces the entry again');
|
|
132
|
+
});
|
|
133
|
+
test('the rotation block gives both scopes a share', async (t) => {
|
|
134
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-scopes-'));
|
|
135
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false });
|
|
136
|
+
t.after(async () => {
|
|
137
|
+
runtime.dispose();
|
|
138
|
+
await rm(dir, { recursive: true, force: true });
|
|
139
|
+
});
|
|
140
|
+
const agent = stubAgent(stubSession(dir));
|
|
141
|
+
await seed(runtime, agent.session, 30, 'global memory');
|
|
142
|
+
for (let index = 0; index < 20; index += 1) {
|
|
143
|
+
await runtime.write(agent.session, {
|
|
144
|
+
scope: 'project',
|
|
145
|
+
title: `project memory ${index}`,
|
|
146
|
+
body: `Body for project memory ${index}.`,
|
|
147
|
+
tags: [],
|
|
148
|
+
}, 'tool');
|
|
149
|
+
}
|
|
150
|
+
assert.ok(await runtime.injectionFor(agent) !== undefined);
|
|
151
|
+
const rotation = await runtime.rotationFor(agent);
|
|
152
|
+
assert.ok(rotation !== undefined);
|
|
153
|
+
const text = textOf(rotation);
|
|
154
|
+
assert.match(text, /\[project\] \[fact\] project memory/u, 'the project scope is represented');
|
|
155
|
+
assert.match(text, /^- \[fact\] global memory/mu, 'and so is the global scope');
|
|
156
|
+
});
|
|
157
|
+
test('/memories stats reports per-scope coverage', async (t) => {
|
|
158
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-stats-'));
|
|
159
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false });
|
|
160
|
+
t.after(async () => {
|
|
161
|
+
runtime.dispose();
|
|
162
|
+
await rm(dir, { recursive: true, force: true });
|
|
163
|
+
});
|
|
164
|
+
const session = stubSession(dir, 'session-stats');
|
|
165
|
+
await seed(runtime, session, 4, 'stat memory');
|
|
166
|
+
const stats = await runtime.stats(session);
|
|
167
|
+
assert.match(stats, /exposure: global 0\/4 \(0\.0%\)/u);
|
|
168
|
+
});
|
|
169
|
+
/** One user-authored message, as the runtime counts it. */
|
|
170
|
+
function userMessage(index) {
|
|
171
|
+
return { role: 'user', source: { kind: 'user' }, content: [{ type: 'text', text: `turn ${index}` }] };
|
|
172
|
+
}
|
|
173
|
+
/** One rotation block already present in the durable history. */
|
|
174
|
+
function rotationMessage() {
|
|
175
|
+
return {
|
|
176
|
+
role: 'user',
|
|
177
|
+
source: { kind: 'plugin:memories', form: 'recall' },
|
|
178
|
+
content: [{ type: 'text', text: '<memory-index>\n- [fact] memory 0\n</memory-index>' }],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
test('a long conversation re-arms the rotation block on its cadence', async (t) => {
|
|
182
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-cadence-'));
|
|
183
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false, rotationEveryTurns: 10 });
|
|
184
|
+
t.after(async () => {
|
|
185
|
+
runtime.dispose();
|
|
186
|
+
await rm(dir, { recursive: true, force: true });
|
|
187
|
+
});
|
|
188
|
+
await seed(runtime, stubAgent(stubSession(dir, 'session-cadence')).session, 60);
|
|
189
|
+
// Turn 5: the first block is due, and only once on this turn.
|
|
190
|
+
const first = stubAgent(stubSession(dir, 'session-cadence', [1, 2, 3, 4, 5].map(userMessage)));
|
|
191
|
+
assert.ok(await runtime.injectionFor(first) !== undefined);
|
|
192
|
+
const blockOne = await runtime.rotationFor(first);
|
|
193
|
+
assert.ok(blockOne !== undefined);
|
|
194
|
+
assert.equal(await runtime.rotationFor(first), undefined, 'the same turn does not emit twice');
|
|
195
|
+
// Turn 10 with one block already in the history: the cadence has not passed.
|
|
196
|
+
const atTen = stubAgent(stubSession(dir, 'session-cadence', [...[1, 2, 3, 4, 5].map(userMessage), rotationMessage(), ...[6, 7, 8, 9, 10].map(userMessage)]));
|
|
197
|
+
assert.equal(await runtime.rotationFor(atTen), undefined, 'the second block is not due until turn 20');
|
|
198
|
+
// Turn 20 with one block: the second is due and differs from the first.
|
|
199
|
+
const atTwenty = stubAgent(stubSession(dir, 'session-cadence', [...[1, 2, 3, 4, 5].map(userMessage), rotationMessage(), ...[6, 7, 8, 9, 10, 11, 12, 13, 14, 15].map(userMessage)]));
|
|
200
|
+
const blockTwo = await runtime.rotationFor(atTwenty);
|
|
201
|
+
assert.ok(blockTwo !== undefined, 'turn 20 earns a second block');
|
|
202
|
+
assert.notEqual(textOf(blockTwo), textOf(blockOne));
|
|
203
|
+
});
|
|
204
|
+
test('rotationEntries: 0 disables the block', async (t) => {
|
|
205
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-off-'));
|
|
206
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false, rotationEntries: 0 });
|
|
207
|
+
t.after(() => runtime.dispose());
|
|
208
|
+
const agent = stubAgent(stubSession(dir));
|
|
209
|
+
await seed(runtime, agent.session, 20);
|
|
210
|
+
assert.ok(await runtime.injectionFor(agent) !== undefined);
|
|
211
|
+
assert.equal(await runtime.rotationFor(agent), undefined);
|
|
212
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
213
|
+
});
|
|
214
|
+
test('a restored conversation that already carries the block does not get another', async (t) => {
|
|
215
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-rot-restart-'));
|
|
216
|
+
const runtime = new MemoriesRuntime(stubContext, { memoriesDir: dir, autoExtract: false });
|
|
217
|
+
t.after(() => runtime.dispose());
|
|
218
|
+
await seed(runtime, stubAgent(stubSession(dir)).session, 20);
|
|
219
|
+
const carried = {
|
|
220
|
+
role: 'user',
|
|
221
|
+
source: { kind: 'plugin:memories', form: 'recall' },
|
|
222
|
+
content: [{ type: 'text', text: '<memory-index>\n- [fact] memory 0\n</memory-index>' }],
|
|
223
|
+
};
|
|
224
|
+
const resumed = stubAgent(stubSession(dir, 'session-restored', [carried]));
|
|
225
|
+
assert.ok(await runtime.injectionFor(resumed) !== undefined, 'the summary is still owed');
|
|
226
|
+
assert.equal(await runtime.rotationFor(resumed), undefined, 'the restored history already has the block');
|
|
227
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
228
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the timing rules: how long a session waits to settle, and which
|
|
3
|
+
* hours the plugin may spend tokens in.
|
|
4
|
+
*
|
|
5
|
+
* Providers price by time of day — DeepSeek doubles its rate on weekday mornings
|
|
6
|
+
* and afternoons (Beijing time) and halves it everywhere else — so these two
|
|
7
|
+
* calculations are what the plugin's entire cost profile hangs on. Both are pure
|
|
8
|
+
* functions with an injected clock, which is why they live in their own module.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-cross-memory/test/schedule
|
|
11
|
+
*/
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import test from 'node:test';
|
|
14
|
+
import { normalizeSettings } from '../config.js';
|
|
15
|
+
import { backgroundDelayMs, cappedBackoffMs, extractionDelayMs, formatDelay, parsePeakHours, peakDelayMs, withinWindow } from '../schedule.js';
|
|
16
|
+
/** The DeepSeek rule this feature was written for: weekday mornings and afternoons. */
|
|
17
|
+
const DEEPSEEK_PEAK = 'Mon-Fri 09:00-12:00, Mon-Fri 14:00-18:00';
|
|
18
|
+
/** A date on a given weekday at a given local time, so tests never guess. */
|
|
19
|
+
function at(weekday, hour, minute = 0) {
|
|
20
|
+
const date = new Date(2026, 8, 1, hour, minute, 0, 0);
|
|
21
|
+
while (date.getDay() !== weekday)
|
|
22
|
+
date.setDate(date.getDate() + 1);
|
|
23
|
+
return date;
|
|
24
|
+
}
|
|
25
|
+
test('a peak spec parses days, times, and reports what it could not read', () => {
|
|
26
|
+
const parsed = parsePeakHours(DEEPSEEK_PEAK);
|
|
27
|
+
assert.deepEqual(parsed.invalid, []);
|
|
28
|
+
assert.equal(parsed.windows.length, 2);
|
|
29
|
+
assert.deepEqual([...parsed.windows[0]?.days ?? []].sort(), [1, 2, 3, 4, 5]);
|
|
30
|
+
assert.equal(parsed.windows[0]?.from, 9 * 60);
|
|
31
|
+
assert.equal(parsed.windows[0]?.to, 12 * 60);
|
|
32
|
+
assert.equal(parsed.windows[1]?.from, 14 * 60);
|
|
33
|
+
// Day spellings and shapes.
|
|
34
|
+
assert.deepEqual([...parsePeakHours('* 09:00-10:00').windows[0]?.days ?? []].sort(), [0, 1, 2, 3, 4, 5, 6]);
|
|
35
|
+
assert.deepEqual([...parsePeakHours('09:00-10:00').windows[0]?.days ?? []].sort(), [0, 1, 2, 3, 4, 5, 6]);
|
|
36
|
+
assert.deepEqual([...parsePeakHours('Mon+Wed 09:00-10:00').windows[0]?.days ?? []].sort(), [1, 3]);
|
|
37
|
+
assert.deepEqual([...parsePeakHours('Sat-Mon 09:00-10:00').windows[0]?.days ?? []].sort(), [0, 1, 6]);
|
|
38
|
+
assert.deepEqual([...parsePeakHours('sat 22:00-02:00').windows[0]?.days ?? []], [6]);
|
|
39
|
+
// An empty spec is "never peak"; nonsense is reported rather than swallowed.
|
|
40
|
+
assert.deepEqual(parsePeakHours(' ').windows, []);
|
|
41
|
+
const broken = parsePeakHours('Mon-Fri 9-12, Xyz 09:00-10:00, Mon-Fri 09:00-09:00');
|
|
42
|
+
assert.equal(broken.windows.length, 0);
|
|
43
|
+
assert.equal(broken.invalid.length, 3);
|
|
44
|
+
});
|
|
45
|
+
test('a peak window covers exactly its own minutes, on exactly its own days', () => {
|
|
46
|
+
const windows = parsePeakHours(DEEPSEEK_PEAK).windows;
|
|
47
|
+
const inside = (date) => windows.some((window) => withinWindow(window, date));
|
|
48
|
+
// 2026-09-01 is a Tuesday, and `at` walks forward from it.
|
|
49
|
+
assert.equal(inside(at(2, 9, 0)), true, 'the first minute counts');
|
|
50
|
+
assert.equal(inside(at(2, 11, 59)), true);
|
|
51
|
+
assert.equal(inside(at(2, 12, 0)), false, 'the last minute does not');
|
|
52
|
+
assert.equal(inside(at(2, 13, 0)), false, 'the lunch gap is off-peak');
|
|
53
|
+
assert.equal(inside(at(2, 14, 0)), true);
|
|
54
|
+
assert.equal(inside(at(2, 18, 0)), false);
|
|
55
|
+
assert.equal(inside(at(2, 3, 0)), false, 'nights are off-peak');
|
|
56
|
+
assert.equal(inside(at(6, 10, 0)), false, 'weekends are entirely off-peak');
|
|
57
|
+
assert.equal(inside(at(0, 15, 0)), false);
|
|
58
|
+
});
|
|
59
|
+
test('peakDelayMs reports the wait to the end of the window, and 0 when free', () => {
|
|
60
|
+
assert.equal(peakDelayMs('', at(2, 10, 0)), 0, 'an empty spec never defers');
|
|
61
|
+
assert.equal(peakDelayMs(DEEPSEEK_PEAK, at(2, 8, 59)), 0);
|
|
62
|
+
assert.equal(peakDelayMs(DEEPSEEK_PEAK, at(2, 10, 0)), 120 * 60_000 + 1_000);
|
|
63
|
+
assert.equal(peakDelayMs(DEEPSEEK_PEAK, at(2, 11, 59)), 61_000, 'one minute left, plus the boundary tick');
|
|
64
|
+
assert.equal(peakDelayMs(DEEPSEEK_PEAK, at(6, 10, 0)), 0);
|
|
65
|
+
// A window that crosses midnight ends the next morning, not tonight.
|
|
66
|
+
assert.equal(peakDelayMs('Sat 22:00-02:00', at(6, 23, 0)), 3 * 3_600_000 + 1_000);
|
|
67
|
+
assert.equal(peakDelayMs('Sat 22:00-02:00', at(0, 1, 0)), 3_600_000 + 1_000);
|
|
68
|
+
});
|
|
69
|
+
test('the settle delay is the larger of the two waits, fractions included', () => {
|
|
70
|
+
// Scheduling for `autoExtractIdleMs` alone produced a pass that could never
|
|
71
|
+
// satisfy `minIdleHours`, and the timer is never re-armed — so with the old
|
|
72
|
+
// defaults (5 minutes against 6 hours) stage 1 never ran at all.
|
|
73
|
+
assert.equal(extractionDelayMs({ autoExtractIdleMs: 300_000, minIdleHours: 6 }), 6 * 3_600_000);
|
|
74
|
+
assert.equal(extractionDelayMs({ autoExtractIdleMs: 300_000, minIdleHours: 0 }), 300_000);
|
|
75
|
+
assert.equal(extractionDelayMs({ autoExtractIdleMs: 300_000, minIdleHours: 0.5 }), 30 * 60_000);
|
|
76
|
+
assert.equal(extractionDelayMs({ autoExtractIdleMs: 8 * 3_600_000, minIdleHours: 6 }), 8 * 3_600_000);
|
|
77
|
+
});
|
|
78
|
+
test('the combined delay also waits out a peak window', () => {
|
|
79
|
+
const settings = { autoExtractIdleMs: 300_000, minIdleHours: 0.5, peakHours: DEEPSEEK_PEAK };
|
|
80
|
+
assert.equal(backgroundDelayMs(settings, at(2, 10, 0)), 120 * 60_000 + 1_000, 'peak dominates a 30 minute wait');
|
|
81
|
+
assert.equal(backgroundDelayMs(settings, at(2, 3, 0)), 30 * 60_000, 'off-peak falls back to the settle wait');
|
|
82
|
+
});
|
|
83
|
+
test('formatDelay reads the way a person would say it', () => {
|
|
84
|
+
assert.equal(formatDelay(45_000), '45s');
|
|
85
|
+
assert.equal(formatDelay(300_000), '5m');
|
|
86
|
+
assert.equal(formatDelay(1_800_000), '30m');
|
|
87
|
+
assert.equal(formatDelay(6 * 3_600_000), '6h');
|
|
88
|
+
assert.equal(formatDelay(6.5 * 3_600_000), '6h30m');
|
|
89
|
+
});
|
|
90
|
+
test('a capped reply backs off geometrically, and changing the knob ends the wait', () => {
|
|
91
|
+
// The window is retried rather than consumed, so the wait is what keeps a
|
|
92
|
+
// ceiling that is simply too small from costing a full-price call every pass.
|
|
93
|
+
assert.equal(cappedBackoffMs(1, 30 * 60_000), 30 * 60_000, 'the first retry is the normal cadence');
|
|
94
|
+
assert.equal(cappedBackoffMs(2, 30 * 60_000), 3_600_000);
|
|
95
|
+
assert.equal(cappedBackoffMs(3, 30 * 60_000), 2 * 3_600_000);
|
|
96
|
+
assert.equal(cappedBackoffMs(4, 30 * 60_000), 4 * 3_600_000);
|
|
97
|
+
assert.equal(cappedBackoffMs(5, 30 * 60_000), 6 * 3_600_000);
|
|
98
|
+
assert.equal(cappedBackoffMs(40, 30 * 60_000), 6 * 3_600_000, 'the ladder has a ceiling, not an ever-growing wait');
|
|
99
|
+
assert.equal(cappedBackoffMs(1, 12 * 3_600_000), 12 * 3_600_000, 'a slower configured cadence is not undercut by the first rung');
|
|
100
|
+
assert.equal(cappedBackoffMs(1, 0), 30 * 60_000, 'periodic checks off leaves the ladder alone');
|
|
101
|
+
assert.equal(cappedBackoffMs(0, 30 * 60_000), 30 * 60_000, 'a count that never got recorded still cools down');
|
|
102
|
+
});
|
|
103
|
+
test('the hour knobs keep fractions instead of truncating them to zero', () => {
|
|
104
|
+
// `minIdleHours: 0.5` used to be truncated to 0, silently disabling the gate
|
|
105
|
+
// the user was trying to tighten.
|
|
106
|
+
const settings = normalizeSettings({ minIdleHours: 0.5, consolidateCooldownHours: 1.5, sweepIntervalHours: 0.5 });
|
|
107
|
+
assert.equal(settings.minIdleHours, 0.5);
|
|
108
|
+
assert.equal(settings.consolidateCooldownHours, 1.5);
|
|
109
|
+
assert.equal(settings.sweepIntervalHours, 0.5);
|
|
110
|
+
assert.equal(normalizeSettings({ minIdleHours: -1 }).minIdleHours, 0, 'still clamps at zero');
|
|
111
|
+
assert.equal(normalizeSettings({ peakHours: ' Mon-Fri 09:00-12:00 ' }).peakHours, 'Mon-Fri 09:00-12:00');
|
|
112
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drift guard for the settings card.
|
|
3
|
+
*
|
|
4
|
+
* The card lists its own field descriptors because it runs in the browser, where
|
|
5
|
+
* the host schema is not importable. A knob the schema declares but the card
|
|
6
|
+
* omits is simply not editable from the GUI, and a card row the schema does not
|
|
7
|
+
* declare fails the save — so the two lists must stay in step, and both must
|
|
8
|
+
* stay in step with the entry schema's live fields. This checks all three as
|
|
9
|
+
* text and as schema metadata, which is also how the host sees them.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-cross-memory/test/settings-card.test
|
|
12
|
+
*/
|
|
13
|
+
import assert from 'node:assert/strict';
|
|
14
|
+
import { readFile } from 'node:fs/promises';
|
|
15
|
+
import test from 'node:test';
|
|
16
|
+
import { MEMORIES_SETTINGS_DEFAULTS, Config } from '../config.js';
|
|
17
|
+
/** The browser half, resolved from the compiled test's own location. */
|
|
18
|
+
const CARD = new URL('../../client/parts/card.js', import.meta.url);
|
|
19
|
+
test('the settings card covers exactly the schema, with bilingual copy', async () => {
|
|
20
|
+
const text = await readFile(CARD, 'utf8');
|
|
21
|
+
const fields = [...text.matchAll(/field: '([A-Za-z][A-Za-z0-9]*)'/gu)].map((match) => match[1]);
|
|
22
|
+
assert.ok(fields.length > 0, 'the card descriptors should be found');
|
|
23
|
+
assert.deepEqual([...fields].sort(), Object.keys(MEMORIES_SETTINGS_DEFAULTS).sort(), 'every tunable needs a card row, and every card row a tunable');
|
|
24
|
+
for (const field of fields) {
|
|
25
|
+
const start = text.indexOf(`field: '${field}'`);
|
|
26
|
+
const block = text.slice(start, text.indexOf('\n },', start));
|
|
27
|
+
assert.match(block, /label: \{ zh: ['"][^'"]+['"]/u, `${field} needs a Chinese label`);
|
|
28
|
+
assert.match(block, /label: \{[^}]*en: ['"][^'"]+['"]/u, `${field} needs an English label`);
|
|
29
|
+
assert.match(block, /hint: \{ zh: ['"]/u, `${field} needs a Chinese hint`);
|
|
30
|
+
// Either quote style is fine: a hint quoting an apostrophe has to use one.
|
|
31
|
+
assert.match(block, /hint: \{[^}]*en: ['"][^'"]+['"]/u, `${field} needs an English hint`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
test('a select control declares its options and the renderer handles the kind', async () => {
|
|
35
|
+
const text = await readFile(CARD, 'utf8');
|
|
36
|
+
const selects = [...text.matchAll(/kind: 'select'/gu)];
|
|
37
|
+
assert.ok(selects.length > 0, 'at least one tunable is an enum');
|
|
38
|
+
for (const match of selects) {
|
|
39
|
+
const block = text.slice(match.index, text.indexOf('label:', match.index));
|
|
40
|
+
assert.match(block, /options: \[/u, 'a select control needs options');
|
|
41
|
+
assert.match(block, /value: '/u, 'each option needs a value');
|
|
42
|
+
}
|
|
43
|
+
assert.match(text, /field\.kind === 'select'/u, 'the renderer must handle the select kind');
|
|
44
|
+
});
|
|
45
|
+
test('the entry schema exposes exactly the tunables as live fields', () => {
|
|
46
|
+
// `toJSON` returns the serialized ref table at runtime while its type still
|
|
47
|
+
// describes the live tree, so the shape is read structurally.
|
|
48
|
+
const json = Config.toJSON();
|
|
49
|
+
const root = json.refs[String(json.uid)];
|
|
50
|
+
const dict = root?.dict;
|
|
51
|
+
assert.ok(dict !== undefined, 'the entry config should serialize as one object node');
|
|
52
|
+
const isLive = (key) => json.refs[String(dict[key])]?.meta?.volatile === true;
|
|
53
|
+
assert.deepEqual(Object.keys(dict).filter(isLive).sort(), Object.keys(MEMORIES_SETTINGS_DEFAULTS).sort(), 'every tunable must be a live field of the entry config, and no other field may be');
|
|
54
|
+
for (const key of ['dshHome', 'memoriesDir', 'projectRootMarkers', 'logFile']) {
|
|
55
|
+
assert.ok(dict[key] !== undefined, `${key} must stay in the entry config`);
|
|
56
|
+
assert.equal(isLive(key), false, `${key} is composition config, not a knob`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for skill drafts and their promotion.
|
|
3
|
+
*
|
|
4
|
+
* The rule under test: a background pass may PROPOSE a skill, but nothing
|
|
5
|
+
* reaches the harness skill catalog until a human promotes it. These tests also
|
|
6
|
+
* pin the file shape the harness loader parses, since a malformed `SKILL.md` is
|
|
7
|
+
* silently ignored rather than reported.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-cross-memory/test/skills.test
|
|
10
|
+
*/
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
import { mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import test from 'node:test';
|
|
16
|
+
import { discardDraft, draftRoot, listDrafts, normalizeSkillName, promote, promotionRoot, renderSkillFile, writeDraft } from '../skills.js';
|
|
17
|
+
/** Two temp roots: a memory store and a harness home. */
|
|
18
|
+
async function roots(t) {
|
|
19
|
+
const memoriesDir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-skills-'));
|
|
20
|
+
const dshHome = await mkdtemp(join(tmpdir(), 'dsh-home-skills-'));
|
|
21
|
+
t.after(async () => {
|
|
22
|
+
await rm(memoriesDir, { recursive: true, force: true });
|
|
23
|
+
await rm(dshHome, { recursive: true, force: true });
|
|
24
|
+
});
|
|
25
|
+
return { memoriesDir, dshHome };
|
|
26
|
+
}
|
|
27
|
+
const DRAFT = { name: 'release-check', description: 'Ship a release safely', steps: ['Run the tests.', 'Tag the commit.', 'Publish.'] };
|
|
28
|
+
test('normalizeSkillName enforces the harness name grammar', () => {
|
|
29
|
+
assert.equal(normalizeSkillName('Release Check'), 'release-check');
|
|
30
|
+
assert.equal(normalizeSkillName(' --Weird__Name-- '), 'weird-name');
|
|
31
|
+
assert.equal(normalizeSkillName(''), undefined);
|
|
32
|
+
assert.equal(normalizeSkillName('---'), undefined);
|
|
33
|
+
});
|
|
34
|
+
test('renderSkillFile emits the frontmatter the loader requires', () => {
|
|
35
|
+
const text = renderSkillFile(DRAFT);
|
|
36
|
+
assert.match(text, /^---\nname: release-check\ndescription: "Ship a release safely"\n---\n/u);
|
|
37
|
+
assert.match(text, /1\. Run the tests\./u);
|
|
38
|
+
assert.match(text, /3\. Publish\./u);
|
|
39
|
+
});
|
|
40
|
+
test('a description that would break a plain YAML scalar is quoted', () => {
|
|
41
|
+
// A mapping colon, a leading indicator, and a quote: all legal in a quoted
|
|
42
|
+
// scalar, all fatal in a plain one — and the loader skips an unparsable skill
|
|
43
|
+
// silently, so the promoted file would never reach the catalog.
|
|
44
|
+
const text = renderSkillFile({ ...DRAFT, description: 'Probe: proves "it" works — see #1' });
|
|
45
|
+
assert.match(text, /^description: "Probe: proves \\"it\\" works — see #1"$/mu);
|
|
46
|
+
assert.match(renderSkillFile({ ...DRAFT, description: 'line one\nline two' }), /^description: "line one\\nline two"$/mu);
|
|
47
|
+
});
|
|
48
|
+
test('a quoted description survives a write/list round trip', async (t) => {
|
|
49
|
+
const { memoriesDir } = await roots(t);
|
|
50
|
+
const description = 'Probe: proves a promoted draft reaches the catalog.';
|
|
51
|
+
await writeDraft(memoriesDir, { ...DRAFT, description });
|
|
52
|
+
const staged = await listDrafts(memoriesDir);
|
|
53
|
+
assert.equal(staged[0]?.description, description);
|
|
54
|
+
});
|
|
55
|
+
test('a draft is staged under the memory store, not the skill root', async (t) => {
|
|
56
|
+
const { memoriesDir, dshHome } = await roots(t);
|
|
57
|
+
const path = await writeDraft(memoriesDir, DRAFT);
|
|
58
|
+
assert.equal(path, join(draftRoot(memoriesDir), 'release-check', 'SKILL.md'));
|
|
59
|
+
assert.match(await readFile(path, 'utf8'), /name: release-check/u);
|
|
60
|
+
// Nothing lands in the catalog yet.
|
|
61
|
+
await assert.rejects(() => stat(promotionRoot(dshHome)), /ENOENT/u);
|
|
62
|
+
const staged = await listDrafts(memoriesDir);
|
|
63
|
+
assert.equal(staged.length, 1);
|
|
64
|
+
assert.equal(staged[0]?.name, 'release-check');
|
|
65
|
+
assert.equal(staged[0]?.description, 'Ship a release safely');
|
|
66
|
+
});
|
|
67
|
+
test('promotion copies the draft into the harness skill root', async (t) => {
|
|
68
|
+
const { memoriesDir, dshHome } = await roots(t);
|
|
69
|
+
await writeDraft(memoriesDir, DRAFT);
|
|
70
|
+
const target = await promote(memoriesDir, dshHome, 'release-check');
|
|
71
|
+
assert.equal(target, join(promotionRoot(dshHome), 'release-check', 'SKILL.md'));
|
|
72
|
+
assert.equal(await readFile(target, 'utf8'), await readFile(join(draftRoot(memoriesDir), 'release-check', 'SKILL.md'), 'utf8'));
|
|
73
|
+
// The draft stays put: the store keeps the provenance.
|
|
74
|
+
assert.equal((await listDrafts(memoriesDir)).length, 1);
|
|
75
|
+
});
|
|
76
|
+
test('promotion is idempotent and reports an unknown name', async (t) => {
|
|
77
|
+
const { memoriesDir, dshHome } = await roots(t);
|
|
78
|
+
await writeDraft(memoriesDir, DRAFT);
|
|
79
|
+
assert.ok(await promote(memoriesDir, dshHome, 'release-check') !== undefined);
|
|
80
|
+
assert.ok(await promote(memoriesDir, dshHome, 'release-check') !== undefined);
|
|
81
|
+
assert.equal(await promote(memoriesDir, dshHome, 'nope'), undefined);
|
|
82
|
+
assert.equal(await promote(memoriesDir, dshHome, '!!!'), undefined);
|
|
83
|
+
});
|
|
84
|
+
test('a promoted skill is a file the loader would parse', async (t) => {
|
|
85
|
+
const { memoriesDir, dshHome } = await roots(t);
|
|
86
|
+
await writeDraft(memoriesDir, DRAFT);
|
|
87
|
+
const target = await promote(memoriesDir, dshHome, 'release-check');
|
|
88
|
+
const text = await readFile(target, 'utf8');
|
|
89
|
+
// The directory-bundle layout is <root>/<name>/SKILL.md with name+description.
|
|
90
|
+
assert.ok(target?.endsWith(join('skills', 'release-check', 'SKILL.md')));
|
|
91
|
+
assert.equal(text.startsWith('---\n'), true);
|
|
92
|
+
assert.match(text, /^name: release-check$/mu);
|
|
93
|
+
assert.match(text, /^description: .+$/mu);
|
|
94
|
+
});
|
|
95
|
+
test('discard removes one staged draft and reports the truth', async (t) => {
|
|
96
|
+
const { memoriesDir } = await roots(t);
|
|
97
|
+
await writeDraft(memoriesDir, DRAFT);
|
|
98
|
+
assert.equal(await discardDraft(memoriesDir, 'release-check'), true);
|
|
99
|
+
assert.equal(await discardDraft(memoriesDir, 'release-check'), false);
|
|
100
|
+
assert.deepEqual(await listDrafts(memoriesDir), []);
|
|
101
|
+
});
|
|
102
|
+
test('staging an invalid name is refused', async (t) => {
|
|
103
|
+
const { memoriesDir } = await roots(t);
|
|
104
|
+
await assert.rejects(() => writeDraft(memoriesDir, { ...DRAFT, name: '!!!' }), /invalid skill name/u);
|
|
105
|
+
});
|
|
106
|
+
test('a draft whose promoted copy is identical is not reported as pending', async (t) => {
|
|
107
|
+
const { memoriesDir, dshHome } = await roots(t);
|
|
108
|
+
await writeDraft(memoriesDir, DRAFT);
|
|
109
|
+
// Before promotion it is pending; without the harness home the filter is off.
|
|
110
|
+
assert.deepEqual((await listDrafts(memoriesDir)).map((draft) => draft.name), ['release-check']);
|
|
111
|
+
assert.deepEqual((await listDrafts(memoriesDir, dshHome)).map((draft) => draft.name), ['release-check']);
|
|
112
|
+
await promote(memoriesDir, dshHome, 'release-check');
|
|
113
|
+
assert.deepEqual(await listDrafts(memoriesDir, dshHome), [], 'a promoted skill is not waiting for anybody');
|
|
114
|
+
assert.deepEqual((await listDrafts(memoriesDir)).map((draft) => draft.name), ['release-check'], 'the draft itself is still there as provenance');
|
|
115
|
+
});
|
|
116
|
+
test('promote refuses to roll a newer live skill back', async (t) => {
|
|
117
|
+
const { memoriesDir, dshHome } = await roots(t);
|
|
118
|
+
await writeDraft(memoriesDir, DRAFT);
|
|
119
|
+
await promote(memoriesDir, dshHome, 'release-check');
|
|
120
|
+
// A human edits the live skill afterwards; the draft is now stale.
|
|
121
|
+
const live = join(promotionRoot(dshHome), 'release-check', 'SKILL.md');
|
|
122
|
+
await writeFile(live, (await readFile(live, 'utf8')).replace('Ship a release safely', 'Ship it with the newer process'), 'utf8');
|
|
123
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
124
|
+
await assert.rejects(() => promote(memoriesDir, dshHome, 'release-check'), /refusing to overwrite/u);
|
|
125
|
+
// And an unchanged draft is a no-op rather than a rewrite.
|
|
126
|
+
await writeDraft(memoriesDir, { ...DRAFT, description: 'edited draft' });
|
|
127
|
+
await promote(memoriesDir, dshHome, 'release-check');
|
|
128
|
+
assert.match(await readFile(live, 'utf8'), /edited draft/u);
|
|
129
|
+
});
|