dsh-prompt-pocket 1.0.4 → 1.0.5
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/index.js +1 -1
- package/package.json +1 -1
- package/scripts/smoke.mjs +22 -2
package/index.js
CHANGED
|
@@ -223,8 +223,8 @@ async function mutate(body) {
|
|
|
223
223
|
const i = at(body.id);
|
|
224
224
|
if (i < 0) return { ok: false, code: 'not-found' };
|
|
225
225
|
entries.splice(i, 1);
|
|
226
|
+
// The tombstone replaces the entry file: same name, different body.
|
|
226
227
|
await writeTombstoneFile({ id: body.id, deletedAt: Date.now() });
|
|
227
|
-
await fs.unlink(path.join(STORE, `${body.id}.json`)).catch(() => {});
|
|
228
228
|
return { ok: true };
|
|
229
229
|
}
|
|
230
230
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-prompt-pocket",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A prompt pocket that floats in the corner: save the draft or the selected text with Ctrl+Shift+S, click a saved prompt to drop it back at the caret.",
|
package/scripts/smoke.mjs
CHANGED
|
@@ -212,9 +212,16 @@ const pass = (n) => ok.push(n);
|
|
|
212
212
|
{
|
|
213
213
|
const dir = path.join(tmp, 'dsh-prompt-stash', 'store.d');
|
|
214
214
|
const files = (await fs.readdir(dir)).filter((f) => f.endsWith('.json'));
|
|
215
|
-
|
|
215
|
+
const victims = [];
|
|
216
|
+
for (const name of files) {
|
|
217
|
+
try {
|
|
218
|
+
const raw = JSON.parse(await fs.readFile(path.join(dir, name), 'utf8'));
|
|
219
|
+
if (typeof raw.deletedAt !== 'number') victims.push(name);
|
|
220
|
+
} catch {}
|
|
221
|
+
}
|
|
222
|
+
assert.ok(victims.length > 0, '应当已经有条目文件');
|
|
216
223
|
const before = (await call('/dsh-prompt-stash/state')).json.total;
|
|
217
|
-
await fs.writeFile(path.join(dir,
|
|
224
|
+
await fs.writeFile(path.join(dir, victims[0]), '{ this is not json', 'utf8');
|
|
218
225
|
const r = await call('/dsh-prompt-stash/state');
|
|
219
226
|
assert.equal(r.status, 200);
|
|
220
227
|
const after = await fs.readdir(dir);
|
|
@@ -317,6 +324,19 @@ const pass = (n) => ok.push(n);
|
|
|
317
324
|
pass('导入缺数组时 400');
|
|
318
325
|
}
|
|
319
326
|
|
|
327
|
+
// 20.5 removing an entry leaves a tombstone file, and it survives the next read
|
|
328
|
+
{
|
|
329
|
+
const saved = await post('/dsh-prompt-stash/mutate', { op: 'save', text: 'to be deleted', scope: 'global' });
|
|
330
|
+
const id = saved.json.entry.id;
|
|
331
|
+
await post('/dsh-prompt-stash/mutate', { op: 'remove', id });
|
|
332
|
+
const file = path.join(tmp, 'dsh-prompt-stash', 'store.d', `${id}.json`);
|
|
333
|
+
const raw = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
334
|
+
assert.equal(typeof raw.deletedAt, 'number', '删除要留下墓碑文件');
|
|
335
|
+
const state = await call('/dsh-prompt-stash/state');
|
|
336
|
+
assert.ok(!state.json.entries.some((e) => e.id === id), '墓碑不能出现在清单里');
|
|
337
|
+
pass('删除留下墓碑文件,清单里不再出现');
|
|
338
|
+
}
|
|
339
|
+
|
|
320
340
|
// 21. git sync: first push creates the branch on the remote
|
|
321
341
|
{
|
|
322
342
|
const remote = path.join(tmp, 'remote.git');
|