quilltap 4.15.0-dev.2 → 4.15.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/README.md +8 -8
- package/lib/__tests__/file-verify-platform.test.js +31 -0
- package/lib/__tests__/find-mount-by-former-name.test.js +60 -0
- package/lib/__tests__/instances-default-json.test.js +18 -0
- package/lib/__tests__/logs-tail-flag.test.js +30 -0
- package/lib/__tests__/maintenance-orphan-sweep.test.js +84 -0
- package/lib/__tests__/migrations-source-ids.test.js +15 -1
- package/lib/db-helpers.js +31 -2
- package/lib/docs-commands.js +9 -1
- package/lib/file-verify-commands.js +20 -3
- package/lib/instances-commands.js +6 -2
- package/lib/instances.js +5 -0
- package/lib/logs-commands.js +14 -2
- package/lib/maintenance-commands.js +35 -6
- package/lib/migrations-commands.js +4 -83
- package/lib/migrations-source.js +109 -0
- package/lib/migrations.generated.js +1039 -0
- package/lib/sync-command.js +7 -0
- package/lib/theme-engine.generated.js +47 -47
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -106,7 +106,7 @@ quilltap instances path # Print the path to ins
|
|
|
106
106
|
quilltap instances set-passphrase Friday # Change or clear the stored passphrase (prompts hidden)
|
|
107
107
|
quilltap instances default Friday # Make it the fall-through for flag-free runs
|
|
108
108
|
quilltap instances rename Friday Weekday # Rename, preserving the stored passphrase
|
|
109
|
-
quilltap instances remove Friday # Unregister (aliases: rm, delete)
|
|
109
|
+
quilltap instances remove Friday # Unregister (aliases: rm, delete); clears the default if it was Friday
|
|
110
110
|
quilltap instances restore-key Friday # Rebuild a lost or passphrase-locked .dbkey
|
|
111
111
|
quilltap instances default --clear # Revert to the OS platform default
|
|
112
112
|
quilltap instances list --json # The registry as JSON, for scripts
|
|
@@ -118,7 +118,7 @@ If an instance's `quilltap.dbkey` goes missing — or its passphrase does — `i
|
|
|
118
118
|
|
|
119
119
|
**It does not re-encrypt character archive bundles.** Those are keyed on the *passphrase*, not the pepper; only the server's Change Passphrase card rewrites them. Bundles made under a passphrase you have just replaced still want the old one.
|
|
120
120
|
|
|
121
|
-
Every subcommand then accepts `--instance <name>` in place of `--data-dir`. The registry lives at `<app-support>/Quilltap/instances.json` (mode 0600; e.g. `~/Library/Application Support/Quilltap/instances.json` on macOS). **Resolution precedence:** `--data-dir` > `--instance` > registered default >
|
|
121
|
+
Every subcommand then accepts `--instance <name>` in place of `--data-dir`. The registry lives at `<app-support>/Quilltap/instances.json` (mode 0600; e.g. `~/Library/Application Support/Quilltap/instances.json` on macOS). **Resolution precedence:** `--data-dir` > `--instance` > `QUILLTAP_DATA_DIR` > registered default > the OS platform default. Pass the **instance root** (e.g. `~/iCloud/Quilltap/Friday`), not its `data/` subdirectory — the CLI appends `data/quilltap.db` itself. `instances list --json` emits the registry (`name`, `path`, `hasPassphrase`, `isDefault`) for scripting.
|
|
122
122
|
|
|
123
123
|
## Database Tool
|
|
124
124
|
|
|
@@ -271,7 +271,7 @@ quilltap docs mvdir <mount> <fromPath> <toPath> # Rename/move a fo
|
|
|
271
271
|
|
|
272
272
|
`ls` flags: `--recursive` / `-R` lists every file below the path, grouped by folder; `--sort name|time|size|links` (default `name`) with `--reverse` / `-r` to flip it; `--links` lists the other mount/path entries under each file that has more than one hard link. `tree` takes `--depth N` (default 20), `--max-nodes N` (default 1000) and `--long`, which is accepted but reserved — it does not yet add columns.
|
|
273
273
|
|
|
274
|
-
Mount arguments accept the mount name (case-insensitive) or a UUID; ambiguous names print candidates and exit non-zero. `--json` is supported by every verb; `reindex`, `embed`, `link`, `rmdir`, and `mvdir` refuse to run without a reachable server. `grep --semantic` goes through `POST /api/v1/mount-points?action=semantic-search`, because the embedding provider lives in the server; it defaults to `--top 20`, `--threshold 0.5`, `--port 3000`.
|
|
274
|
+
Mount arguments accept the mount name (case-insensitive) or a UUID; ambiguous names print candidates and exit non-zero. A renamed store still answers to a name it used to carry (the `formerNames` column), with a note on stderr saying which store was found, until another store takes that name; the UUID is the reference that never changes. `--json` is supported by every verb; `reindex`, `embed`, `link`, `rmdir`, and `mvdir` refuse to run without a reachable server. `grep --semantic` goes through `POST /api/v1/mount-points?action=semantic-search`, because the embedding provider lives in the server; it defaults to `--top 20`, `--threshold 0.5`, `--port 3000`.
|
|
275
275
|
|
|
276
276
|
### Addressing documents with `qtap://` URIs
|
|
277
277
|
|
|
@@ -284,7 +284,7 @@ quilltap docs grep --mount qtap://notes/ "TODO"
|
|
|
284
284
|
quilltap docs find --uri Manifesto
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
-
The URI authority is matched name-first, UUID
|
|
287
|
+
The URI authority is matched name-first, then UUID, then a former name — the same rule as a bare `<mount>` (`qtap://<store name>/…` or `qtap://<uuid>/…`). Two-target verbs (`move` / `copy` / `link` / `mvdir`) take either two `qtap://` URIs or the four legacy positionals; `find` and `grep` take one via `--mount`.
|
|
288
288
|
|
|
289
289
|
**CLI limitation:** the CLI addresses document stores only. `qtap://self/…` needs a character context, and there is none at a shell prompt, so it is rejected with guidance; `qtap://project/…` and `qtap://general/…` are likewise not CLI-addressable — pass a store name or UUID instead.
|
|
290
290
|
|
|
@@ -442,7 +442,7 @@ quilltap maintenance status --instance Friday --json
|
|
|
442
442
|
quilltap maintenance run --instance Friday # Run the sweeps once (lock-gated; refuses while the server is up)
|
|
443
443
|
```
|
|
444
444
|
|
|
445
|
-
`maintenance run` is a DB writer: it claims `<dataDir>/quilltap.lock` and **refuses while a running Quilltap server holds it** — stop the server first. Because it can only run with the server down, it performs the sweeps expressible as direct SQL/filesystem work: reaping finished background jobs (COMPLETED after 7 days, DEAD after 30, keyed off `completedAt`), closed terminal sessions older than 30 days plus their transcript files, and orphaned mount-index files. The **stale-chat asset collapse** (superseded story-backgrounds and wardrobe avatars) needs the server's file-storage machinery and runs only on the server's daily tick — `status` reports a stale-chat count so you can see the backlog. Retention windows mirror `lib/background-jobs/maintenance/retention-constants.ts`.
|
|
445
|
+
`maintenance run` is a DB writer: it claims `<dataDir>/quilltap.lock` and **refuses while a running Quilltap server holds it** — stop the server first. Because it can only run with the server down, it performs the sweeps expressible as direct SQL/filesystem work: reaping finished background jobs (COMPLETED after 7 days, DEAD after 30, keyed off `completedAt`), closed terminal sessions older than 30 days plus their transcript files, and orphaned mount-index files (each with its stored document or blob content). The **stale-chat asset collapse** (superseded story-backgrounds and wardrobe avatars) needs the server's file-storage machinery and runs only on the server's daily tick — `status` reports a stale-chat count so you can see the backlog. Retention windows mirror `lib/background-jobs/maintenance/retention-constants.ts`.
|
|
446
446
|
|
|
447
447
|
## Logs
|
|
448
448
|
|
|
@@ -467,11 +467,11 @@ quilltap migrations pending # Just the not-yet-recorded list
|
|
|
467
467
|
quilltap migrations run --dry-run # List what would run (refuses without --dry-run)
|
|
468
468
|
```
|
|
469
469
|
|
|
470
|
-
`--json` works on all three. "Not yet recorded" includes migrations whose `shouldRun()` is `false` on this instance — the CLI doesn't evaluate the predicate, so it can't distinguish "would skip" from "would run."
|
|
470
|
+
`--json` works on all three. Run from a source checkout, the CLI reads the migration list live from `migrations/scripts/`; an npm-installed CLI uses the list bundled with its release, so it reports the migrations that version of Quilltap contains. "Not yet recorded" includes migrations whose `shouldRun()` is `false` on this instance — the CLI doesn't evaluate the predicate, so it can't distinguish "would skip" from "would run."
|
|
471
471
|
|
|
472
472
|
## File Verification
|
|
473
473
|
|
|
474
|
-
`quilltap file-verify` force-downloads an instance's cloud-evicted (dataless) top-level data files so the databases are fully local before anything opens them. It reads each placeholder, which faults it in through the cloud provider (iCloud Drive, etc.). Safe to run repeatedly — a no-op when nothing is evicted. macOS only for now.
|
|
474
|
+
`quilltap file-verify` force-downloads an instance's cloud-evicted (dataless) top-level data files so the databases are fully local before anything opens them. It reads each placeholder, which faults it in through the cloud provider (iCloud Drive, etc.). Safe to run repeatedly — a no-op when nothing is evicted. Evicted-file detection is macOS only for now: on other platforms no file is reported as evicted (a sparse or compressed Linux file would otherwise look evicted), the command says so, and `--all` still reads every top-level file.
|
|
475
475
|
|
|
476
476
|
```bash
|
|
477
477
|
quilltap file-verify --instance Ignite # Fault in only the dataless top-level files
|
|
@@ -479,7 +479,7 @@ quilltap file-verify --instance Friday --all # Read every top-level file, not j
|
|
|
479
479
|
quilltap file-verify --instance Friday --json # Machine-readable report
|
|
480
480
|
```
|
|
481
481
|
|
|
482
|
-
Only the **top-level** files of the data directory are considered; the `backups/` subdirectory is left alone. Flags: `--all` (read every top-level file, not just dataless ones), `--stall-ms <ms>` (treat a download as stalled after this many ms with no bytes per chunk; default 30000), `--json
|
|
482
|
+
Only the **top-level** files of the data directory are considered; the `backups/` subdirectory is left alone. Flags: `--all` (read every top-level file, not just dataless ones), `--stall-ms <ms>` (treat a download as stalled after this many ms with no bytes per chunk; default 30000), `--json` (the report includes `detectionSupported`, `false` off macOS). Resolves the instance via the usual `--instance` / `--data-dir` plumbing.
|
|
483
483
|
|
|
484
484
|
## Theme Management
|
|
485
485
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quilltap file-verify` detects evicted files on macOS only (issue #359).
|
|
3
|
+
*
|
|
4
|
+
* The blocks*512 < size test also matches a sparse or compressed file on
|
|
5
|
+
* Linux, and Windows reports no block count, so other platforms must never
|
|
6
|
+
* flag a file. Mirrors the darwin gate in lib/startup/materialize-cloud-files.ts.
|
|
7
|
+
*
|
|
8
|
+
* @jest-environment node
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const { isDatalessStat, isDetectionSupported } = require('../file-verify-commands');
|
|
14
|
+
|
|
15
|
+
describe('file-verify evicted-file detection', () => {
|
|
16
|
+
const sparse = { size: 10 * 1024 * 1024, blocks: 0 };
|
|
17
|
+
const resident = { size: 4096, blocks: 8 };
|
|
18
|
+
|
|
19
|
+
it('flags an under-allocated file on macOS', () => {
|
|
20
|
+
expect(isDetectionSupported('darwin')).toBe(true);
|
|
21
|
+
expect(isDatalessStat(sparse, 'darwin')).toBe(true);
|
|
22
|
+
expect(isDatalessStat(resident, 'darwin')).toBe(false);
|
|
23
|
+
expect(isDatalessStat({ size: 0, blocks: 0 }, 'darwin')).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it.each(['linux', 'win32'])('never flags a file on %s', (platform) => {
|
|
27
|
+
expect(isDetectionSupported(platform)).toBe(false);
|
|
28
|
+
expect(isDatalessStat(sparse, platform)).toBe(false);
|
|
29
|
+
expect(isDatalessStat({ size: 4096, blocks: undefined }, platform)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI looks a document store up by name in SQL, so it mirrors the last
|
|
3
|
+
* step of the server's `matchStoreRef` itself: a store still answers to a name
|
|
4
|
+
* it used to carry (`doc_mount_points.formerNames`), so a script written
|
|
5
|
+
* before a rename keeps working. Never a guess: two claimants match neither,
|
|
6
|
+
* and a database from before the column existed has no former names.
|
|
7
|
+
*
|
|
8
|
+
* @jest-environment node
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
// The real driver: `better-sqlite3` is auto-mocked for unit tests.
|
|
16
|
+
const Database = require(path.join(process.cwd(), 'node_modules', 'better-sqlite3'));
|
|
17
|
+
const { findMountByFormerName } = require('../db-helpers');
|
|
18
|
+
|
|
19
|
+
let db;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
db = new Database(':memory:');
|
|
23
|
+
db.exec(`CREATE TABLE doc_mount_points (id TEXT PRIMARY KEY, name TEXT NOT NULL, formerNames TEXT NOT NULL DEFAULT '[]')`);
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => db.close());
|
|
26
|
+
|
|
27
|
+
const insert = (id, name, formerNames) =>
|
|
28
|
+
db.prepare('INSERT INTO doc_mount_points (id, name, formerNames) VALUES (?, ?, ?)').run(id, name, formerNames);
|
|
29
|
+
|
|
30
|
+
it('finds the store that used to carry the name, ignoring case and surrounding space', () => {
|
|
31
|
+
insert('a', 'Novel', JSON.stringify(['Novel Drafts']));
|
|
32
|
+
insert('b', 'Lore', '[]');
|
|
33
|
+
expect(findMountByFormerName(db, ' novel drafts ')).toMatchObject({ id: 'a', name: 'Novel' });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('finds nothing for a name no store used to carry', () => {
|
|
37
|
+
insert('a', 'Novel', JSON.stringify(['Novel Drafts']));
|
|
38
|
+
expect(findMountByFormerName(db, 'Lore')).toBeNull();
|
|
39
|
+
expect(findMountByFormerName(db, '')).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('matches neither store when two claim one former name', () => {
|
|
43
|
+
insert('a', 'One', JSON.stringify(['Shared']));
|
|
44
|
+
insert('b', 'Two', JSON.stringify(['shared']));
|
|
45
|
+
expect(findMountByFormerName(db, 'Shared')).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('reads a malformed column as no former names', () => {
|
|
49
|
+
insert('a', 'Novel', 'not json');
|
|
50
|
+
insert('b', 'Lore', JSON.stringify({ not: 'an array' }));
|
|
51
|
+
expect(findMountByFormerName(db, 'Novel Drafts')).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('finds nothing in a database from before stores kept their former names', () => {
|
|
55
|
+
const old = new Database(':memory:');
|
|
56
|
+
old.exec('CREATE TABLE doc_mount_points (id TEXT PRIMARY KEY, name TEXT NOT NULL)');
|
|
57
|
+
old.prepare('INSERT INTO doc_mount_points (id, name) VALUES (?, ?)').run('a', 'Novel');
|
|
58
|
+
expect(findMountByFormerName(old, 'Novel Drafts')).toBeNull();
|
|
59
|
+
old.close();
|
|
60
|
+
});
|
|
@@ -84,6 +84,24 @@ describe('instances default --json', () => {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
describe('instances remove', () => {
|
|
88
|
+
it('clears the default when the default instance is removed (issue #360)', () => {
|
|
89
|
+
addInstance('Friday');
|
|
90
|
+
addInstance('Ignite');
|
|
91
|
+
run('default', 'Friday');
|
|
92
|
+
expect(run('remove', 'Friday')).toMatch(/default is now cleared/);
|
|
93
|
+
expect(run('default')).toBe('(none)');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('keeps the default when another instance is removed', () => {
|
|
97
|
+
addInstance('Friday');
|
|
98
|
+
addInstance('Ignite');
|
|
99
|
+
run('default', 'Friday');
|
|
100
|
+
expect(run('remove', 'Ignite')).not.toMatch(/default is now cleared/);
|
|
101
|
+
expect(run('default')).toBe('Friday');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
87
105
|
describe('instances list --json', () => {
|
|
88
106
|
it('emits the registry as an array', () => {
|
|
89
107
|
expect(JSON.parse(run('list', '--json'))).toEqual([]);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quilltap logs --tail 0` means the whole file (issue #361).
|
|
3
|
+
*
|
|
4
|
+
* The flag was parsed as `parseInt(value, 10) || 100`, and 0 is falsy, so the
|
|
5
|
+
* documented "0 = full file" became the default of 100 lines.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const { parseFlags } = require('../logs-commands');
|
|
13
|
+
|
|
14
|
+
describe('logs --tail', () => {
|
|
15
|
+
it('defaults to 100 lines', () => {
|
|
16
|
+
expect(parseFlags([]).tail).toBe(100);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('keeps 0, which means the whole file', () => {
|
|
20
|
+
expect(parseFlags(['--tail', '0']).tail).toBe(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('takes a positive count', () => {
|
|
24
|
+
expect(parseFlags(['--tail', '250']).tail).toBe(250);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each(['abc', '-5', ''])('falls back to 100 for %p', (value) => {
|
|
28
|
+
expect(parseFlags(['--tail', value]).tail).toBe(100);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quilltap maintenance run`, step 3: the orphaned mount-index file sweep.
|
|
3
|
+
*
|
|
4
|
+
* A mount index whose tables came from the schema translator carries no
|
|
5
|
+
* foreign keys, so deleting a `doc_mount_files` row cascades to nothing. The
|
|
6
|
+
* sweep therefore deletes an orphan's document and blob payload itself, as the
|
|
7
|
+
* server's `gcOrphanedFileRow` does. A bare `DELETE FROM doc_mount_files`
|
|
8
|
+
* (what this step used to run) left that payload behind for good.
|
|
9
|
+
*
|
|
10
|
+
* @jest-environment node
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const path = require('path');
|
|
16
|
+
// The real driver, by absolute path: jest maps the bare specifier to a mock.
|
|
17
|
+
const Database = require(path.join(process.cwd(), 'node_modules', 'better-sqlite3'));
|
|
18
|
+
const { sweepOrphanedMountFiles } = require('../maintenance-commands');
|
|
19
|
+
|
|
20
|
+
// The tables as the schema translator creates them: no REFERENCES anywhere.
|
|
21
|
+
function createIndex({ withDocuments = true, withBlobs = true } = {}) {
|
|
22
|
+
const db = new Database(':memory:');
|
|
23
|
+
db.exec('CREATE TABLE doc_mount_files (id TEXT PRIMARY KEY, sha256 TEXT)');
|
|
24
|
+
db.exec('CREATE TABLE doc_mount_file_links (id TEXT PRIMARY KEY, fileId TEXT, mountPointId TEXT)');
|
|
25
|
+
if (withDocuments) db.exec('CREATE TABLE doc_mount_documents (id TEXT PRIMARY KEY, fileId TEXT, content TEXT)');
|
|
26
|
+
if (withBlobs) db.exec('CREATE TABLE doc_mount_blobs (id TEXT PRIMARY KEY, fileId TEXT, data BLOB)');
|
|
27
|
+
return db;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ids = (db, table, column = 'id') =>
|
|
31
|
+
db.prepare(`SELECT ${column} AS v FROM ${table} ORDER BY v`).all().map((row) => row.v);
|
|
32
|
+
|
|
33
|
+
describe('sweepOrphanedMountFiles', () => {
|
|
34
|
+
it('deletes an orphaned file row together with its document and blob payload', () => {
|
|
35
|
+
const db = createIndex();
|
|
36
|
+
db.exec(`
|
|
37
|
+
INSERT INTO doc_mount_files VALUES ('linked', 'a'), ('orphan-doc', 'b'), ('orphan-blob', 'c');
|
|
38
|
+
INSERT INTO doc_mount_file_links VALUES ('link-1', 'linked', 'mp-1');
|
|
39
|
+
INSERT INTO doc_mount_documents VALUES ('d-linked', 'linked', 'kept'), ('d-orphan', 'orphan-doc', 'gone');
|
|
40
|
+
INSERT INTO doc_mount_blobs VALUES ('b-linked', 'linked', x'01'), ('b-orphan', 'orphan-blob', x'02');
|
|
41
|
+
`);
|
|
42
|
+
|
|
43
|
+
expect(sweepOrphanedMountFiles(db)).toBe(2);
|
|
44
|
+
|
|
45
|
+
expect(ids(db, 'doc_mount_files')).toEqual(['linked']);
|
|
46
|
+
expect(ids(db, 'doc_mount_documents')).toEqual(['d-linked']);
|
|
47
|
+
expect(ids(db, 'doc_mount_blobs')).toEqual(['b-linked']);
|
|
48
|
+
expect(ids(db, 'doc_mount_file_links')).toEqual(['link-1']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('leaves content alone while any link, in any store, still references it', () => {
|
|
52
|
+
const db = createIndex();
|
|
53
|
+
db.exec(`
|
|
54
|
+
INSERT INTO doc_mount_files VALUES ('shared', 'a');
|
|
55
|
+
INSERT INTO doc_mount_file_links VALUES ('link-1', 'shared', 'mp-1'), ('link-2', 'shared', 'mp-2');
|
|
56
|
+
INSERT INTO doc_mount_documents VALUES ('d-shared', 'shared', 'kept');
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
expect(sweepOrphanedMountFiles(db)).toBe(0);
|
|
60
|
+
expect(ids(db, 'doc_mount_files')).toEqual(['shared']);
|
|
61
|
+
expect(ids(db, 'doc_mount_documents')).toEqual(['d-shared']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('copes with an index that never created a payload table', () => {
|
|
65
|
+
// Both payload tables are minted lazily; a document-only index has no
|
|
66
|
+
// `doc_mount_blobs`, and deleting from a missing table would throw.
|
|
67
|
+
const db = createIndex({ withBlobs: false });
|
|
68
|
+
db.exec(`
|
|
69
|
+
INSERT INTO doc_mount_files VALUES ('orphan', 'a');
|
|
70
|
+
INSERT INTO doc_mount_documents VALUES ('d-orphan', 'orphan', 'gone');
|
|
71
|
+
`);
|
|
72
|
+
|
|
73
|
+
expect(sweepOrphanedMountFiles(db)).toBe(1);
|
|
74
|
+
expect(ids(db, 'doc_mount_documents')).toEqual([]);
|
|
75
|
+
|
|
76
|
+
const bare = createIndex({ withDocuments: false, withBlobs: false });
|
|
77
|
+
bare.exec("INSERT INTO doc_mount_files VALUES ('orphan', 'a')");
|
|
78
|
+
expect(sweepOrphanedMountFiles(bare)).toBe(1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('does nothing on a database with no mount-index tables', () => {
|
|
82
|
+
expect(sweepOrphanedMountFiles(new Database(':memory:'))).toBe(0);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
|
|
16
|
-
const { extractMigrationId } = require('../migrations-
|
|
16
|
+
const { extractMigrationId, extractMigrationsFromSource, loadMigrationList } = require('../migrations-source');
|
|
17
17
|
|
|
18
18
|
describe('extractMigrationId', () => {
|
|
19
19
|
it('reads a string-literal id', () => {
|
|
@@ -52,3 +52,17 @@ describe('every migration script yields an id', () => {
|
|
|
52
52
|
expect(missing).toEqual([]);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
describe('the migration list an npm-installed CLI reads (issue #362)', () => {
|
|
57
|
+
const scriptsDir = path.join(__dirname, '..', '..', '..', '..', 'migrations', 'scripts');
|
|
58
|
+
|
|
59
|
+
it('ships a generated list that matches the source', () => {
|
|
60
|
+
expect(require('../migrations.generated.js')).toEqual(extractMigrationsFromSource(scriptsDir));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('falls back to the generated list when there is no source folder', () => {
|
|
64
|
+
const list = loadMigrationList(path.join(__dirname, 'no-such-folder'));
|
|
65
|
+
expect(list).toBe(require('../migrations.generated.js'));
|
|
66
|
+
expect(list.length).toBeGreaterThan(100);
|
|
67
|
+
});
|
|
68
|
+
});
|
package/lib/db-helpers.js
CHANGED
|
@@ -31,8 +31,9 @@ function resolveDataDir(overrideDir) {
|
|
|
31
31
|
// Precedence order (highest to lowest):
|
|
32
32
|
// 1. --data-dir (explicit override)
|
|
33
33
|
// 2. --instance (explicit instance)
|
|
34
|
-
// 3.
|
|
35
|
-
//
|
|
34
|
+
// 3. QUILLTAP_DATA_DIR env var (an Ariel terminal sets it, so a bare
|
|
35
|
+
// `quilltap` there addresses the instance the terminal belongs to)
|
|
36
|
+
// 4. registered default instance
|
|
36
37
|
// 5. OS platform default
|
|
37
38
|
//
|
|
38
39
|
// Returns `usedPlatformDefault: true` only when falling back to the true
|
|
@@ -369,7 +370,35 @@ function resolveProject(db, query) {
|
|
|
369
370
|
return fuzzy[0];
|
|
370
371
|
}
|
|
371
372
|
|
|
373
|
+
/**
|
|
374
|
+
* The one document store that used to carry `spec` as its name, or null. A
|
|
375
|
+
* store keeps its former names (`doc_mount_points.formerNames`, JSON) so an
|
|
376
|
+
* address written before a rename still reaches it; this mirrors the last step
|
|
377
|
+
* of the server's `matchStoreRef`. Callers try the current name and the UUID
|
|
378
|
+
* first, since the holder of a name always wins it. Two stores claiming one
|
|
379
|
+
* former name match neither. A database from before the column existed has no
|
|
380
|
+
* former names.
|
|
381
|
+
*/
|
|
382
|
+
function findMountByFormerName(db, spec) {
|
|
383
|
+
const hasColumn = db
|
|
384
|
+
.prepare("SELECT 1 FROM pragma_table_info('doc_mount_points') WHERE name = 'formerNames'")
|
|
385
|
+
.get();
|
|
386
|
+
if (!hasColumn) return null;
|
|
387
|
+
const needle = String(spec).trim().toLowerCase();
|
|
388
|
+
if (!needle) return null;
|
|
389
|
+
const holders = db.prepare('SELECT * FROM doc_mount_points').all().filter((row) => {
|
|
390
|
+
try {
|
|
391
|
+
const former = JSON.parse(row.formerNames || '[]');
|
|
392
|
+
return Array.isArray(former) && former.some((name) => String(name).trim().toLowerCase() === needle);
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
return holders.length === 1 ? holders[0] : null;
|
|
398
|
+
}
|
|
399
|
+
|
|
372
400
|
module.exports = {
|
|
401
|
+
findMountByFormerName,
|
|
373
402
|
resolveDataDir,
|
|
374
403
|
resolveDataDirAndPassphrase,
|
|
375
404
|
printDefaultInstanceHint,
|
package/lib/docs-commands.js
CHANGED
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
printDefaultInstanceHint,
|
|
9
9
|
loadDbKey,
|
|
10
10
|
openMountIndexDb,
|
|
11
|
+
findMountByFormerName,
|
|
11
12
|
} = require('./db-helpers');
|
|
12
13
|
const { isQtapUri, parseQtapUri, formatDocStoreUri } = require('./qtap-uri');
|
|
13
14
|
|
|
@@ -93,7 +94,8 @@ Write subcommands (server required for database-backed mounts):
|
|
|
93
94
|
mvdir <mount> <fromPath> <toPath> Rename/move a folder (server-required)
|
|
94
95
|
|
|
95
96
|
<mount> may be a mount name or UUID. Names are case-insensitive; ambiguous
|
|
96
|
-
names print candidates and exit non-zero.
|
|
97
|
+
names print candidates and exit non-zero. A renamed store still answers to a
|
|
98
|
+
name it used to carry, until another store takes that name.
|
|
97
99
|
|
|
98
100
|
Addressing with qtap:// URIs: anywhere a <mount> <relativePath> pair is taken,
|
|
99
101
|
you may instead pass a single qtap:// URI in its place — e.g.
|
|
@@ -399,6 +401,12 @@ function requireMount(db, spec) {
|
|
|
399
401
|
ORDER BY name COLLATE NOCASE`
|
|
400
402
|
).all(spec);
|
|
401
403
|
if (rows.length === 0) {
|
|
404
|
+
// No store holds the name now; one may have carried it before a rename.
|
|
405
|
+
const renamed = findMountByFormerName(db, spec);
|
|
406
|
+
if (renamed) {
|
|
407
|
+
console.error(`Note: "${spec}" is a former name of "${renamed.name}".`);
|
|
408
|
+
return renamed;
|
|
409
|
+
}
|
|
402
410
|
console.error(`No mount point found with name "${spec}"`);
|
|
403
411
|
process.exit(1);
|
|
404
412
|
}
|
|
@@ -36,9 +36,15 @@ const STAT_BLOCK_BYTES = 512;
|
|
|
36
36
|
// and the partially-materialized file (blocks > 0 but blocks*512 < size) — the
|
|
37
37
|
// latter still fails SQLite open with "file is not a database". A fully-resident
|
|
38
38
|
// file always reports blocks*512 >= size (allocation rounds up), so this never
|
|
39
|
-
// flags a healthy file. Zero-byte files are never flagged. Other platforms
|
|
40
|
-
//
|
|
41
|
-
|
|
39
|
+
// flags a healthy file. Zero-byte files are never flagged. Other platforms are a
|
|
40
|
+
// no-op, as in the server's materializeCloudFiles: on Linux a sparse or
|
|
41
|
+
// compressed file would read as evicted, and Windows reports no block count.
|
|
42
|
+
function isDetectionSupported(platform = process.platform) {
|
|
43
|
+
return platform === 'darwin';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isDatalessStat(stat, platform = process.platform) {
|
|
47
|
+
if (!isDetectionSupported(platform)) return false;
|
|
42
48
|
return stat.size > 0 && stat.blocks * STAT_BLOCK_BYTES < stat.size;
|
|
43
49
|
}
|
|
44
50
|
|
|
@@ -166,11 +172,20 @@ async function fileVerifyCommand(args) {
|
|
|
166
172
|
// resolved.dataDir already points at the instance's data/ directory.
|
|
167
173
|
const targetDir = resolved.dataDir;
|
|
168
174
|
|
|
175
|
+
const supported = isDetectionSupported();
|
|
176
|
+
if (!supported && !flags.json) {
|
|
177
|
+
console.log(
|
|
178
|
+
'Evicted-file detection is supported on macOS only; on this platform no file is reported as evicted.' +
|
|
179
|
+
(flags.all ? '' : ' Pass --all to read every top-level file anyway.'),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
169
183
|
const files = listTopLevelFiles(targetDir);
|
|
170
184
|
const targets = flags.all ? files : files.filter((f) => f.dataless);
|
|
171
185
|
|
|
172
186
|
const summary = {
|
|
173
187
|
dataDir: targetDir,
|
|
188
|
+
detectionSupported: supported,
|
|
174
189
|
checked: files.length,
|
|
175
190
|
targeted: targets.length,
|
|
176
191
|
downloaded: 0,
|
|
@@ -226,4 +241,6 @@ async function fileVerifyCommand(args) {
|
|
|
226
241
|
|
|
227
242
|
module.exports = {
|
|
228
243
|
fileVerifyCommand,
|
|
244
|
+
isDatalessStat,
|
|
245
|
+
isDetectionSupported,
|
|
229
246
|
};
|
|
@@ -54,8 +54,8 @@ will also accept --instance <name>:
|
|
|
54
54
|
quilltap docs --instance Lebanon list
|
|
55
55
|
|
|
56
56
|
Default Instance:
|
|
57
|
-
When no --instance or --data-dir is specified, the CLI uses
|
|
58
|
-
|
|
57
|
+
When no --instance or --data-dir is specified, the CLI uses QUILLTAP_DATA_DIR
|
|
58
|
+
(if set), then the registered default (if one is set), then the OS platform
|
|
59
59
|
default. Marked with * in list output.
|
|
60
60
|
|
|
61
61
|
quilltap instances default Friday # set Friday as the default
|
|
@@ -223,8 +223,12 @@ function cmdRemove(args) {
|
|
|
223
223
|
console.error('Usage: quilltap instances remove <name>');
|
|
224
224
|
process.exit(1);
|
|
225
225
|
}
|
|
226
|
+
const defaultBefore = getDefaultInstance();
|
|
226
227
|
const key = removeInstance(name);
|
|
227
228
|
console.log(`Removed instance "${key}".`);
|
|
229
|
+
if (defaultBefore === key) {
|
|
230
|
+
console.log('It was the default instance; the default is now cleared.');
|
|
231
|
+
}
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
async function cmdSetPassphrase(args) {
|
package/lib/instances.js
CHANGED
|
@@ -198,6 +198,11 @@ function removeInstance(name) {
|
|
|
198
198
|
throw new Error(`Unknown instance "${name}".`);
|
|
199
199
|
}
|
|
200
200
|
delete registry.instances[key];
|
|
201
|
+
// A default that names a removed instance would send every flagless command
|
|
202
|
+
// to the platform default without a word (issue #360).
|
|
203
|
+
if (registry.defaultInstance === key) {
|
|
204
|
+
registry.defaultInstance = null;
|
|
205
|
+
}
|
|
201
206
|
writeInstances(registry);
|
|
202
207
|
return key;
|
|
203
208
|
}
|
package/lib/logs-commands.js
CHANGED
|
@@ -71,6 +71,17 @@ function colorizeLogLine(line) {
|
|
|
71
71
|
return `${color}${line}${RESET}`;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const DEFAULT_TAIL = 100;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Parse a --tail value. 0 is a real answer (the whole file), so only a value
|
|
78
|
+
* that is not a non-negative integer falls back to the default (issue #361).
|
|
79
|
+
*/
|
|
80
|
+
function parseTail(value) {
|
|
81
|
+
const n = parseInt(value, 10);
|
|
82
|
+
return Number.isNaN(n) || n < 0 ? DEFAULT_TAIL : n;
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
/**
|
|
75
86
|
* Parse command-line arguments for the logs command.
|
|
76
87
|
*/
|
|
@@ -80,7 +91,7 @@ function parseFlags(args) {
|
|
|
80
91
|
instance: '',
|
|
81
92
|
passphrase: '',
|
|
82
93
|
stream: 'combined',
|
|
83
|
-
tail:
|
|
94
|
+
tail: DEFAULT_TAIL,
|
|
84
95
|
follow: false,
|
|
85
96
|
grep: '',
|
|
86
97
|
help: false,
|
|
@@ -102,7 +113,7 @@ function parseFlags(args) {
|
|
|
102
113
|
} else if (arg === '--stream') {
|
|
103
114
|
flags.stream = args[++i];
|
|
104
115
|
} else if (arg === '--tail') {
|
|
105
|
-
flags.tail =
|
|
116
|
+
flags.tail = parseTail(args[++i]);
|
|
106
117
|
} else if (arg === '--grep') {
|
|
107
118
|
flags.grep = args[++i];
|
|
108
119
|
}
|
|
@@ -380,4 +391,5 @@ async function logsCommand(args) {
|
|
|
380
391
|
|
|
381
392
|
module.exports = {
|
|
382
393
|
logsCommand,
|
|
394
|
+
parseFlags,
|
|
383
395
|
};
|
|
@@ -228,6 +228,39 @@ async function handleStatus(flags) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Delete every `doc_mount_files` row that no link references, with its
|
|
233
|
+
* payload. Returns how many file rows went.
|
|
234
|
+
*
|
|
235
|
+
* The payload rows (`doc_mount_documents`, `doc_mount_blobs`) are deleted
|
|
236
|
+
* explicitly, before the file row: a mount index whose tables came from the
|
|
237
|
+
* schema translator carries no foreign keys, so nothing cascades and a bare
|
|
238
|
+
* delete of the file row would keep its payload forever. This MIRRORS the
|
|
239
|
+
* server's `gcOrphanedFileRow` (`lib/mount-index/orphan-store-reaper.ts`),
|
|
240
|
+
* which `sweepOrphanedFiles` runs for each orphan. Keep them in step. Both
|
|
241
|
+
* payload tables are created lazily, so each is checked for first.
|
|
242
|
+
*
|
|
243
|
+
* One transaction: a failure part-way leaves nothing half-collected.
|
|
244
|
+
*/
|
|
245
|
+
function sweepOrphanedMountFiles(mountsDb) {
|
|
246
|
+
const tableExists = (name) =>
|
|
247
|
+
!!mountsDb.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(name);
|
|
248
|
+
if (!tableExists('doc_mount_files') || !tableExists('doc_mount_file_links')) return 0;
|
|
249
|
+
|
|
250
|
+
const orphaned = 'SELECT id FROM doc_mount_files WHERE id NOT IN (SELECT DISTINCT fileId FROM doc_mount_file_links)';
|
|
251
|
+
const sweep = mountsDb.transaction(() => {
|
|
252
|
+
for (const payloadTable of ['doc_mount_documents', 'doc_mount_blobs']) {
|
|
253
|
+
if (tableExists(payloadTable)) {
|
|
254
|
+
mountsDb.prepare(`DELETE FROM ${payloadTable} WHERE fileId IN (${orphaned})`).run();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return mountsDb
|
|
258
|
+
.prepare('DELETE FROM doc_mount_files WHERE id NOT IN (SELECT DISTINCT fileId FROM doc_mount_file_links)')
|
|
259
|
+
.run().changes;
|
|
260
|
+
});
|
|
261
|
+
return sweep();
|
|
262
|
+
}
|
|
263
|
+
|
|
231
264
|
async function handleRun(flags) {
|
|
232
265
|
let resolved;
|
|
233
266
|
let pepper;
|
|
@@ -321,12 +354,7 @@ async function handleRun(flags) {
|
|
|
321
354
|
// be absent on older instances — skip gracefully.
|
|
322
355
|
try {
|
|
323
356
|
mountsDb = openMountIndexDb(resolved.dataDir, pepper, { readonly: false });
|
|
324
|
-
summary.orphanedFiles = mountsDb
|
|
325
|
-
.prepare(
|
|
326
|
-
'DELETE FROM doc_mount_files ' +
|
|
327
|
-
'WHERE id NOT IN (SELECT DISTINCT fileId FROM doc_mount_file_links)'
|
|
328
|
-
)
|
|
329
|
-
.run().changes;
|
|
357
|
+
summary.orphanedFiles = sweepOrphanedMountFiles(mountsDb);
|
|
330
358
|
} catch {
|
|
331
359
|
summary.orphanedFiles = 0;
|
|
332
360
|
}
|
|
@@ -391,4 +419,5 @@ async function maintenanceCommand(args) {
|
|
|
391
419
|
|
|
392
420
|
module.exports = {
|
|
393
421
|
maintenanceCommand,
|
|
422
|
+
sweepOrphanedMountFiles,
|
|
394
423
|
};
|