knowpool 0.0.0-stage → 0.1.0-alpha.2
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 +101 -2
- package/bin/knowpool.mjs +150 -0
- package/docs/DESIGN.md +111 -0
- package/docs/NAMING.md +65 -0
- package/docs/PROTOCOL.md +146 -0
- package/docs/ROADMAP.md +33 -0
- package/docs/architecture/BUILD.md +36 -0
- package/docs/architecture/README.md +125 -0
- package/docs/architecture/mermaid.json +18 -0
- package/docs/architecture/print.css +58 -0
- package/docs/architecture/print.py +121 -0
- package/docs/architecture/sources/evidence.mmd +13 -0
- package/docs/architecture/sources/export.mmd +11 -0
- package/docs/architecture/sources/review.mmd +12 -0
- package/docs/architecture/sources/sync.mmd +18 -0
- package/docs/architecture/sources/system.mmd +13 -0
- package/docs/architecture/sources/team.mmd +14 -0
- package/docs/architecture/sources/vaults.mmd +14 -0
- package/docs/architecture/svg/evidence.svg +1 -0
- package/docs/architecture/svg/export.svg +1 -0
- package/docs/architecture/svg/review.svg +1 -0
- package/docs/architecture/svg/sync.svg +1 -0
- package/docs/architecture/svg/system.svg +1 -0
- package/docs/architecture/svg/team.svg +1 -0
- package/docs/architecture/svg/vaults.svg +1 -0
- package/docs/design-history/README.md +25 -0
- package/docs/design-history/icons/kbloom.svg +1 -0
- package/docs/design-history/icons/knowary.svg +1 -0
- package/docs/design-history/icons/knowcommit.svg +1 -0
- package/docs/design-history/icons/knowcrate.svg +1 -0
- package/docs/design-history/icons/knowmill.svg +1 -0
- package/docs/design-history/icons/lorekiln.svg +1 -0
- package/docs/design-history/icons/loreparcel.svg +1 -0
- package/docs/design-history/icons/loreyard.svg +1 -0
- package/docs/design-history/icons/zhicang.svg +1 -0
- package/docs/design-history/original-layouts.md +100 -0
- package/examples/demo.mjs +54 -0
- package/examples/review.html +10 -0
- package/package.json +13 -4
- package/skills/knowpool/SKILL.md +16 -0
- package/src/contexts.mjs +44 -0
- package/src/export.mjs +107 -0
- package/src/extract.py +68 -0
- package/src/io.mjs +129 -0
- package/src/notes.mjs +132 -0
- package/src/pr.mjs +32 -0
- package/src/setup.mjs +63 -0
- package/src/sources.mjs +136 -0
- package/src/storage.mjs +87 -0
- package/src/vault.mjs +78 -0
- package/src/versioning.mjs +198 -0
- package/test/adapters.test.mjs +60 -0
- package/test/audit.test.mjs +129 -0
- package/test/fixtures/two-pages.pdf +87 -0
- package/test/release.test.mjs +126 -0
- package/test/support.mjs +56 -0
- package/test/workflow.test.mjs +193 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
4
|
+
import { once } from 'node:events';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { cli, context, env, propose } from './support.mjs';
|
|
9
|
+
|
|
10
|
+
test('saved HTML → reviewed note → bare Git → new checkout → identical original', () => {
|
|
11
|
+
const demo = fileURLToPath(new URL('../examples/demo.mjs', import.meta.url));
|
|
12
|
+
const p = spawnSync(process.execPath, [demo], { env, encoding: 'utf8' });
|
|
13
|
+
assert.equal(p.status, 0, p.stderr);
|
|
14
|
+
const receipt = JSON.parse(p.stdout);
|
|
15
|
+
assert.equal(receipt.verified.notes, 1);
|
|
16
|
+
assert.equal(receipt.byteIdentical, true);
|
|
17
|
+
assert.match(receipt.evidence, /450 毫秒/);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('immutable CAS, stable first filename, idempotent init and lossless export', t => {
|
|
21
|
+
const c = context(t);
|
|
22
|
+
const first = c.ok('source', 'add', c.file('first.docx', Buffer.from([12, 0, 255, 66])));
|
|
23
|
+
const second = c.ok('source', 'add', c.file('second.docx', Buffer.from([12, 0, 255, 66])));
|
|
24
|
+
assert.equal(first.id, second.id);
|
|
25
|
+
assert.equal(second.filename, 'first.docx');
|
|
26
|
+
assert.equal(second.duplicate, true);
|
|
27
|
+
assert.equal(c.ok('init').id, c.id);
|
|
28
|
+
const dest = path.join(c.root, 'export.docx');
|
|
29
|
+
c.ok('source', 'get', first.id, '--out', dest);
|
|
30
|
+
assert.deepEqual(readFileSync(dest), Buffer.from([12, 0, 255, 66]));
|
|
31
|
+
writeFileSync(dest, 'user file');
|
|
32
|
+
assert.equal(c.fail('source', 'get', first.id, '--out', dest), 'INTEGRITY');
|
|
33
|
+
assert.equal(readFileSync(dest, 'utf8'), 'user file');
|
|
34
|
+
assert.equal(c.fail('source', 'read', '../knowpool.json', '--at', 'line:1'), 'ID');
|
|
35
|
+
assert.equal(c.fail('source', 'read', first.id, '--at', 'page:1'), 'LOCATOR');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('review digest follows exact draft bytes, base revision and repeated approval', t => {
|
|
39
|
+
const c = context(t);
|
|
40
|
+
const src = c.ok('source', 'add', c.file('meeting.md', '会议\n证据甲\n'));
|
|
41
|
+
const first = propose(c, src);
|
|
42
|
+
const location = path.join(c.vault, '.knowpool', 'drafts', first.draft + '.json');
|
|
43
|
+
const record = JSON.parse(readFileSync(location, 'utf8'));
|
|
44
|
+
record.markdown += '\n修订草案\n';
|
|
45
|
+
writeFileSync(location, JSON.stringify(record));
|
|
46
|
+
assert.equal(c.fail('approve', first.draft, '--digest', first.digest), 'REVIEW_CHANGED');
|
|
47
|
+
const review = c.ok('draft', 'show', first.draft);
|
|
48
|
+
c.ok('approve', first.draft, '--digest', review.digest);
|
|
49
|
+
assert.equal(c.ok('approve', first.draft, '--digest', review.digest).repeated, true);
|
|
50
|
+
const a = propose(c, src, '新方向甲', ['--update', first.note]);
|
|
51
|
+
const b = propose(c, src, '新方向乙', ['--update', first.note]);
|
|
52
|
+
c.ok('approve', b.draft, '--digest', b.digest);
|
|
53
|
+
assert.equal(c.fail('approve', a.draft, '--digest', a.digest), 'STALE');
|
|
54
|
+
assert.equal(c.ok('show', first.note).note.body, '新方向乙');
|
|
55
|
+
assert.equal(c.fail('source', 'read', src.id, '--at', 'line:7'), 'LOCATOR');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('concurrent writers produce exactly one accepted update', async t => {
|
|
59
|
+
const c = context(t);
|
|
60
|
+
const src = c.ok('source', 'add', c.file('note.txt', 'header\none\n'));
|
|
61
|
+
const first = propose(c, src);
|
|
62
|
+
c.ok('approve', first.draft, '--digest', first.digest);
|
|
63
|
+
const drafts = ['左侧更新', '右侧更新'].map(body => propose(c, src, body, ['--update', first.note]));
|
|
64
|
+
const results = await Promise.all(drafts.map(async d => {
|
|
65
|
+
const child = spawn(process.execPath, [cli, '--vault', c.vault, 'approve', d.draft, '--digest', d.digest], { env });
|
|
66
|
+
let err = '';
|
|
67
|
+
child.stderr.on('data', c => { err += c; });
|
|
68
|
+
const [code] = await once(child, 'close');
|
|
69
|
+
return code === 0 ? 'ok' : JSON.parse(err).error;
|
|
70
|
+
}));
|
|
71
|
+
assert.equal(results.filter(s => s === 'ok').length, 1);
|
|
72
|
+
assert(results.some(s => s === 'STALE' || s === 'BUSY'));
|
|
73
|
+
assert(['左侧更新', '右侧更新'].includes(c.ok('show', first.note).note.body));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('team contributions become searchable only after merge into local main', t => {
|
|
77
|
+
const c = context(t, 'team');
|
|
78
|
+
c.ok('commit', '--message', 'initialize team vault');
|
|
79
|
+
c.ok(...c.sync);
|
|
80
|
+
const input = c.file('test.txt', '演示\n试点\n');
|
|
81
|
+
assert.equal(c.fail('source', 'add', input), 'BRANCH');
|
|
82
|
+
c.git('-C', c.vault, 'switch', '-c', 'knowledge/asr-pilot');
|
|
83
|
+
const src = c.ok('source', 'add', input);
|
|
84
|
+
const d = propose(c, src);
|
|
85
|
+
c.ok('approve', d.draft, '--digest', d.digest);
|
|
86
|
+
c.ok('commit', '--message', 'propose pilot');
|
|
87
|
+
c.ok(...c.sync);
|
|
88
|
+
assert.equal(c.ok('search', '决策').matches.length, 0);
|
|
89
|
+
assert.match(c.git('-C', c.vault, 'diff', '--stat', 'main...HEAD'), /knowledge\/note_/);
|
|
90
|
+
c.git('-C', c.vault, 'switch', 'main');
|
|
91
|
+
c.git('-C', c.vault, 'merge', '--ff-only', 'knowledge/asr-pilot');
|
|
92
|
+
assert.equal(c.ok('search', '决策').matches[0].id, d.note);
|
|
93
|
+
assert.equal(c.ok('history').commits.length, 2);
|
|
94
|
+
assert.equal(c.fail(...c.sync), 'BRANCH');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('corrupt or missing objects stop publication and restore without replacing bytes', t => {
|
|
98
|
+
const c = context(t);
|
|
99
|
+
c.ok('commit', '--message', 'bootstrap');
|
|
100
|
+
const before = c.ok(...c.sync).commit;
|
|
101
|
+
const src = c.ok('source', 'add', c.file('r.txt', 'payload'));
|
|
102
|
+
c.ok('commit', '--message', 'record source');
|
|
103
|
+
const localObject = path.join(c.vault, '.knowpool', 'objects', 'sha256', src.sha256.slice(0, 2), src.sha256);
|
|
104
|
+
const folder = path.join(c.store, c.id, 'objects', 'sha256', src.sha256.slice(0, 2));
|
|
105
|
+
mkdirSync(folder, { recursive: true });
|
|
106
|
+
const target = path.join(folder, src.sha256);
|
|
107
|
+
writeFileSync(target, 'payloae');
|
|
108
|
+
assert.equal(c.fail(...c.sync), 'INTEGRITY');
|
|
109
|
+
assert.equal(c.git('--git-dir', c.bare, 'rev-parse', 'main'), before);
|
|
110
|
+
rmSync(target);
|
|
111
|
+
rmSync(localObject);
|
|
112
|
+
assert.equal(c.fail(...c.sync), 'FILE');
|
|
113
|
+
assert.equal(c.git('--git-dir', c.bare, 'rev-parse', 'main'), before);
|
|
114
|
+
c.ok('source', 'add', path.join(c.root, 'r.txt'));
|
|
115
|
+
const pushed = c.ok(...c.sync);
|
|
116
|
+
assert.equal(c.ok(...c.sync).commit, pushed.commit);
|
|
117
|
+
const clone = path.join(c.root, 'restored');
|
|
118
|
+
c.git('clone', c.bare, clone);
|
|
119
|
+
writeFileSync(target, 'payloae');
|
|
120
|
+
const bad = c.invoke(clone, 'restore', '--store', c.store);
|
|
121
|
+
assert.equal(JSON.parse(bad.stderr).error, 'INTEGRITY');
|
|
122
|
+
assert(!existsSync(path.join(clone, '.knowpool', 'objects', 'sha256', src.sha256.slice(0, 2), src.sha256)));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('non-fast-forward push and cross-vault destination preserve the receiving ref', t => {
|
|
126
|
+
const c = context(t);
|
|
127
|
+
c.ok('commit', '--message', 'initial');
|
|
128
|
+
c.ok(...c.sync);
|
|
129
|
+
const clone = path.join(c.root, 'clone');
|
|
130
|
+
c.git('clone', c.bare, clone);
|
|
131
|
+
c.at(clone, 'source', 'add', c.file('b.txt', 'second clone'));
|
|
132
|
+
c.at(clone, 'commit', '--message', 'from B');
|
|
133
|
+
const tip = c.at(clone, ...c.sync).commit;
|
|
134
|
+
c.ok('source', 'add', c.file('a.txt', 'first clone'));
|
|
135
|
+
c.ok('commit', '--message', 'from A');
|
|
136
|
+
assert.equal(c.fail(...c.sync), 'TOOL');
|
|
137
|
+
assert.equal(c.git('--git-dir', c.bare, 'rev-parse', 'main'), tip);
|
|
138
|
+
const other = context(t);
|
|
139
|
+
other.ok('commit', '--message', 'unrelated vault');
|
|
140
|
+
assert.equal(other.fail('sync', '--git-dir', c.bare, '--store', c.store), 'VAULT');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('push checks reachable history, including removed references and unexpected tracked files', t => {
|
|
144
|
+
const c = context(t);
|
|
145
|
+
const src = c.ok('source', 'add', c.file('brief.txt', 'first version'));
|
|
146
|
+
const originalRev = c.ok('commit', '--message', 'record original').commit;
|
|
147
|
+
rmSync(path.join(c.vault, 'sources', src.id + '.json'));
|
|
148
|
+
c.ok('commit', '--message', 'remove current reference');
|
|
149
|
+
writeFileSync(path.join(c.vault, 'scratch.txt'), 'private scratch');
|
|
150
|
+
assert.equal(c.ok(...c.sync).verifiedObjects, 1);
|
|
151
|
+
const clone = path.join(c.root, 'history-clone');
|
|
152
|
+
c.git('clone', c.bare, clone);
|
|
153
|
+
assert(!existsSync(path.join(clone, 'scratch.txt')));
|
|
154
|
+
c.git('-C', clone, 'checkout', '--detach', originalRev);
|
|
155
|
+
assert.equal(c.at(clone, 'restore', '--store', c.store).sources, 1);
|
|
156
|
+
assert.equal(c.at(clone, 'source', 'read', src.id, '--at', 'line:1').text, 'first version');
|
|
157
|
+
const rawPath = path.join(c.vault, 'raw.bin');
|
|
158
|
+
writeFileSync(rawPath, 'local only');
|
|
159
|
+
c.git('-C', c.vault, 'add', 'raw.bin');
|
|
160
|
+
assert.equal(c.fail('commit', '--message', 'should not send unrelated index'), 'STAGED');
|
|
161
|
+
c.git('-C', c.vault, 'commit', '-m', 'manually staged a raw file');
|
|
162
|
+
c.git('-C', c.vault, 'rm', 'raw.bin');
|
|
163
|
+
c.git('-C', c.vault, 'commit', '-m', 'deleted later');
|
|
164
|
+
assert.equal(c.fail(...c.sync), 'HISTORY');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('project skill installation preserves local edits and refuses symlinked managed directories', t => {
|
|
168
|
+
const c = context(t);
|
|
169
|
+
const { installed } = c.ok('skill', 'install');
|
|
170
|
+
assert.equal(c.ok('skill', 'install').installed, installed);
|
|
171
|
+
assert.match(readFileSync(installed, 'utf8'), /name: knowpool/);
|
|
172
|
+
writeFileSync(installed, 'local customization');
|
|
173
|
+
assert.equal(c.fail('skill', 'install'), 'EXISTS');
|
|
174
|
+
assert(c.git('-C', c.vault, 'check-ignore', installed));
|
|
175
|
+
symlinkSync(c.store, path.join(c.vault, 'sources'), 'dir');
|
|
176
|
+
assert.equal(c.fail('source', 'add', c.file('example.md', 'note')), 'PATH');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('init adopts an empty directory, preserves nonempty folders and is repeatable', t => {
|
|
180
|
+
const c = context(t);
|
|
181
|
+
const empty = path.join(c.root, 'empty');
|
|
182
|
+
mkdirSync(empty);
|
|
183
|
+
const created = c.at(empty, 'init', '--mode', 'team');
|
|
184
|
+
assert.equal(c.at(empty, 'init').id, created.id);
|
|
185
|
+
assert.deepEqual(c.at(empty, 'history').commits, []);
|
|
186
|
+
assert.equal(c.at(empty, 'search', 'anything').ref, 'unborn-main');
|
|
187
|
+
const ordinary = path.join(c.root, 'ordinary');
|
|
188
|
+
mkdirSync(ordinary);
|
|
189
|
+
writeFileSync(path.join(ordinary, 'mine.md'), 'keep this');
|
|
190
|
+
assert.equal(JSON.parse(c.invoke(ordinary, 'init').stderr).error, 'VAULT');
|
|
191
|
+
assert(!existsSync(path.join(ordinary, '.git')));
|
|
192
|
+
assert.equal(readFileSync(path.join(ordinary, 'mine.md'), 'utf8'), 'keep this');
|
|
193
|
+
});
|