@git-stunts/git-cas 5.3.0 → 5.3.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/CHANGELOG.md +16 -0
- package/README.md +12 -3
- package/bin/actions.js +6 -3
- package/bin/git-cas.js +11 -3
- package/bin/io.js +86 -0
- package/package.json +1 -1
- package/src/domain/services/CasService.js +30 -9
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [5.3.2] — Unreleased
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- **Vitest workspace split** — unit, integration, and benchmark suites now live in explicit workspace projects so the integration suite always runs with `fileParallelism: false`, regardless of the exact CLI invocation shape.
|
|
12
|
+
- **Status semantics** — `STATUS.md` now distinguishes the last released version (`v5.3.1`) from the current branch version (`v5.3.2`).
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- **CLI version drift** — `bin/git-cas.js` now reads the package version instead of carrying a stale hardcoded literal, so `git-cas --version` tracks the in-repo release line correctly.
|
|
16
|
+
|
|
17
|
+
## [5.3.1] — 2026-03-15
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- **Repeated chunk tree emission** — `createTree()` and `_createMerkleTree()` now emit one chunk blob tree entry per unique digest, preserving first-seen order at write time while leaving the manifest unchanged as the authoritative ordered index of chunk occurrences.
|
|
21
|
+
- **Invalid Git trees for repetitive content** — repetitive files no longer produce duplicate tree entry names, so emitted trees pass `git fsck --full` without `duplicateEntries` failures.
|
|
22
|
+
- **Regression coverage for tree reachability** — added unit tests for first-seen dedupe behavior and integration tests that store repetitive content, verify restore correctness, and assert clean `git fsck` results on a real Git repository.
|
|
23
|
+
|
|
8
24
|
## [5.3.0] — 2026-03-08
|
|
9
25
|
|
|
10
26
|
### Added
|
package/README.md
CHANGED
|
@@ -32,12 +32,23 @@ We use the object database.
|
|
|
32
32
|
- **Lifecycle management** `readManifest`, `inspectAsset`, `collectReferencedChunks` — inspect trees, plan deletions, audit storage.
|
|
33
33
|
- **Vault** GC-safe ref-based storage. One ref (`refs/cas/vault`) indexes all assets by slug. No more silent data loss from `git gc`.
|
|
34
34
|
- **Interactive dashboard** `git cas inspect` with chunk heatmap, animated progress bars, and rich manifest views.
|
|
35
|
-
- **Verify & JSON output** `git cas verify` checks integrity; `--json` on all commands for CI/scripting.
|
|
35
|
+
- **Verify & JSON output** `git cas verify` checks integrity; `--json` on all current human-facing commands provides convenient structured output for CI/scripting.
|
|
36
36
|
|
|
37
37
|
**Use it for:** binary assets, build artifacts, model weights, data packs, secret bundles, weird experiments, etc.
|
|
38
38
|
|
|
39
39
|
<img src="./docs/demo.gif" alt="git-cas demo" />
|
|
40
40
|
|
|
41
|
+
## What's new in v5.3.1
|
|
42
|
+
|
|
43
|
+
**Patch release — repeated chunk tree fix.**
|
|
44
|
+
|
|
45
|
+
- **Unique chunk tree entries** — `createTree()` and `_createMerkleTree()` now emit one tree entry per unique chunk digest instead of repeating the same filename for repeated chunk occurrences.
|
|
46
|
+
- **Manifest remains authoritative** — chunk order and multiplicity still come entirely from the manifest; restore behavior is unchanged.
|
|
47
|
+
- **Clean `git fsck` on repetitive files** — repetitive content no longer yields duplicate tree filenames or `duplicateEntries` errors.
|
|
48
|
+
- **New regressions** — unit and integration coverage now exercises repeated-chunk files and validates real Git tree integrity with `git fsck --full`.
|
|
49
|
+
|
|
50
|
+
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
51
|
+
|
|
41
52
|
## What's new in v5.3.0
|
|
42
53
|
|
|
43
54
|
**M16 Capstone — audit remediation, CLI configuration, and security hardening.**
|
|
@@ -56,8 +67,6 @@ We use the object database.
|
|
|
56
67
|
- **Constructor validation** — `chunkSize`, `maxRestoreBufferSize`, `maxEncryptionBufferSize` validated at construction time.
|
|
57
68
|
- **Cross-runtime portability** — `Error.captureStackTrace` guarded, crypto adapter contracts normalized.
|
|
58
69
|
|
|
59
|
-
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
60
|
-
|
|
61
70
|
## What's new in v5.2.3
|
|
62
71
|
|
|
63
72
|
**Internal refactoring — no breaking API changes.** The facade, CasService, and crypto adapters were restructured for better separation of concerns:
|
package/bin/actions.js
CHANGED
|
@@ -70,10 +70,13 @@ function defaultDelay(ms) {
|
|
|
70
70
|
*
|
|
71
71
|
* @param {(...args: any[]) => Promise<void>} fn - The async action function.
|
|
72
72
|
* @param {() => boolean} getJson - Lazy getter for --json flag value.
|
|
73
|
-
* @param {{ delay?: (ms: number) => Promise<void
|
|
73
|
+
* @param {{ delay?: (ms: number) => Promise<void>, setExitCode?: (code: number) => void }} [options] - Injectable dependencies.
|
|
74
74
|
* @returns {(...args: any[]) => Promise<void>} Wrapped action.
|
|
75
75
|
*/
|
|
76
|
-
export function runAction(fn, getJson, {
|
|
76
|
+
export function runAction(fn, getJson, {
|
|
77
|
+
delay = defaultDelay,
|
|
78
|
+
setExitCode = (code) => { process.exitCode = code; },
|
|
79
|
+
} = {}) {
|
|
77
80
|
return async (/** @type {any[]} */ ...args) => {
|
|
78
81
|
try {
|
|
79
82
|
await fn(...args);
|
|
@@ -81,8 +84,8 @@ export function runAction(fn, getJson, { delay = defaultDelay } = {}) {
|
|
|
81
84
|
if (err?.code === 'INTEGRITY_ERROR') {
|
|
82
85
|
await delay(1000);
|
|
83
86
|
}
|
|
87
|
+
setExitCode(1);
|
|
84
88
|
writeError(err, getJson());
|
|
85
|
-
process.exitCode = 1;
|
|
86
89
|
}
|
|
87
90
|
};
|
|
88
91
|
}
|
package/bin/git-cas.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
4
6
|
import { program, Option } from 'commander';
|
|
5
7
|
import GitPlumbing, { ShellRunnerFactory } from '@git-stunts/plumbing';
|
|
6
8
|
import ContentAddressableStore, { EventEmitterObserver, CborCodec } from '../index.js';
|
|
@@ -11,16 +13,23 @@ import { renderHistoryTimeline } from './ui/history-timeline.js';
|
|
|
11
13
|
import { renderManifestView } from './ui/manifest-view.js';
|
|
12
14
|
import { renderHeatmap } from './ui/heatmap.js';
|
|
13
15
|
import { runAction } from './actions.js';
|
|
16
|
+
import { flushStdioAndExit, installBrokenPipeHandlers } from './io.js';
|
|
14
17
|
import { filterEntries, formatTable, formatTabSeparated } from './ui/vault-list.js';
|
|
15
18
|
import { readPassphraseFile, promptPassphrase } from './ui/passphrase-prompt.js';
|
|
16
19
|
import { loadConfig, mergeConfig } from './config.js';
|
|
17
20
|
|
|
21
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const { version: CLI_VERSION } = JSON.parse(
|
|
23
|
+
readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'),
|
|
24
|
+
);
|
|
25
|
+
|
|
18
26
|
const getJson = () => program.opts().json;
|
|
27
|
+
installBrokenPipeHandlers();
|
|
19
28
|
|
|
20
29
|
program
|
|
21
30
|
.name('git-cas')
|
|
22
31
|
.description('Content Addressable Storage backed by Git')
|
|
23
|
-
.version(
|
|
32
|
+
.version(CLI_VERSION)
|
|
24
33
|
.option('-q, --quiet', 'Suppress progress output')
|
|
25
34
|
.option('--json', 'Output results as JSON');
|
|
26
35
|
|
|
@@ -751,5 +760,4 @@ await program.parseAsync();
|
|
|
751
760
|
|
|
752
761
|
// Flush stdout/stderr before exiting — spawned git child processes leave
|
|
753
762
|
// libuv handles that prevent natural exit in containerized environments.
|
|
754
|
-
|
|
755
|
-
process.stdout.write('', () => process.stderr.write('', () => process.exit(code)));
|
|
763
|
+
await flushStdioAndExit();
|
package/bin/io.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {unknown} err
|
|
5
|
+
* @returns {err is NodeJS.ErrnoException}
|
|
6
|
+
*/
|
|
7
|
+
function isBrokenPipeError(err) {
|
|
8
|
+
return Boolean(err && typeof err === 'object' && /** @type {NodeJS.ErrnoException} */ (err).code === 'EPIPE');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Install stdout/stderr error handlers that exit cleanly when the downstream
|
|
13
|
+
* consumer closes the pipe before the CLI finishes writing.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} [options]
|
|
16
|
+
* @param {{ on(event: string, listener: (...args: any[]) => void): any, removeListener(event: string, listener: (...args: any[]) => void): any }} [options.stdout]
|
|
17
|
+
* @param {{ on(event: string, listener: (...args: any[]) => void): any, removeListener(event: string, listener: (...args: any[]) => void): any }} [options.stderr]
|
|
18
|
+
* @param {(code?: number) => never} [options.exit]
|
|
19
|
+
* @param {() => number} [options.getExitCode]
|
|
20
|
+
* @returns {{ dispose(): void }}
|
|
21
|
+
*/
|
|
22
|
+
export function installBrokenPipeHandlers({
|
|
23
|
+
stdout = process.stdout,
|
|
24
|
+
stderr = process.stderr,
|
|
25
|
+
exit = process.exit,
|
|
26
|
+
getExitCode = () => process.exitCode || 0,
|
|
27
|
+
} = {}) {
|
|
28
|
+
const onError = (/** @type {unknown} */ err) => {
|
|
29
|
+
if (isBrokenPipeError(err)) {
|
|
30
|
+
exit(getExitCode());
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
stdout.on('error', onError);
|
|
35
|
+
stderr.on('error', onError);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
dispose() {
|
|
39
|
+
stdout.removeListener('error', onError);
|
|
40
|
+
stderr.removeListener('error', onError);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Flush stdout/stderr before exit so the CLI does not hang on open handles in
|
|
47
|
+
* containerized test environments.
|
|
48
|
+
*
|
|
49
|
+
* @param {Object} [options]
|
|
50
|
+
* @param {{ write(chunk: string, callback?: () => void): boolean }} [options.stdout]
|
|
51
|
+
* @param {{ write(chunk: string, callback?: () => void): boolean }} [options.stderr]
|
|
52
|
+
* @param {(code?: number) => void} [options.exit]
|
|
53
|
+
* @param {number} [options.code]
|
|
54
|
+
* @returns {Promise<void>}
|
|
55
|
+
*/
|
|
56
|
+
export async function flushStdioAndExit({
|
|
57
|
+
stdout = process.stdout,
|
|
58
|
+
stderr = process.stderr,
|
|
59
|
+
exit = process.exit,
|
|
60
|
+
code = process.exitCode || 0,
|
|
61
|
+
} = {}) {
|
|
62
|
+
await flushStream(stdout);
|
|
63
|
+
await flushStream(stderr);
|
|
64
|
+
exit(code);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {{ write(chunk: string, callback?: () => void): boolean }} stream
|
|
69
|
+
* @returns {Promise<void>}
|
|
70
|
+
*/
|
|
71
|
+
async function flushStream(stream) {
|
|
72
|
+
try {
|
|
73
|
+
await new Promise((resolve) => {
|
|
74
|
+
stream.write('', resolve);
|
|
75
|
+
});
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (!isBrokenPipeError(err)) {
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Give stream error handlers one turn to observe late EPIPE events before exit.
|
|
83
|
+
await delay(0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { isBrokenPipeError };
|
package/package.json
CHANGED
|
@@ -320,11 +320,37 @@ export default class CasService {
|
|
|
320
320
|
return data;
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Builds unique chunk blob tree entries in first-seen order.
|
|
325
|
+
*
|
|
326
|
+
* Tree entries keep chunk blobs reachable in Git. The manifest remains the
|
|
327
|
+
* authoritative ordered list of chunk occurrences, so repeated digests only
|
|
328
|
+
* need one tree entry.
|
|
329
|
+
*
|
|
330
|
+
* @private
|
|
331
|
+
* @param {import('../value-objects/Chunk.js').default[]} chunks
|
|
332
|
+
* @returns {string[]}
|
|
333
|
+
*/
|
|
334
|
+
_createChunkTreeEntries(chunks) {
|
|
335
|
+
const treeEntries = [];
|
|
336
|
+
const seenDigests = new Set();
|
|
337
|
+
|
|
338
|
+
for (const chunk of chunks) {
|
|
339
|
+
if (seenDigests.has(chunk.digest)) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
seenDigests.add(chunk.digest);
|
|
343
|
+
treeEntries.push(`100644 blob ${chunk.blob}\t${chunk.digest}`);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return treeEntries;
|
|
347
|
+
}
|
|
348
|
+
|
|
323
349
|
/**
|
|
324
350
|
* Creates a Git tree object from a manifest.
|
|
325
351
|
*
|
|
326
|
-
* The tree contains the serialized manifest file and one blob entry per
|
|
327
|
-
*
|
|
352
|
+
* The tree contains the serialized manifest file and one blob entry per
|
|
353
|
+
* unique chunk digest, preserving first-seen order.
|
|
328
354
|
*
|
|
329
355
|
* @param {Object} options
|
|
330
356
|
* @param {import('../value-objects/Manifest.js').default} options.manifest - The file manifest.
|
|
@@ -342,7 +368,7 @@ export default class CasService {
|
|
|
342
368
|
|
|
343
369
|
const treeEntries = [
|
|
344
370
|
`100644 blob ${manifestOid}\tmanifest.${this.codec.extension}`,
|
|
345
|
-
...
|
|
371
|
+
...this._createChunkTreeEntries(chunks),
|
|
346
372
|
];
|
|
347
373
|
|
|
348
374
|
return await this.persistence.writeTree(treeEntries);
|
|
@@ -358,7 +384,6 @@ export default class CasService {
|
|
|
358
384
|
async _createMerkleTree({ manifest }) {
|
|
359
385
|
const chunks = [...manifest.chunks];
|
|
360
386
|
const subManifestRefs = [];
|
|
361
|
-
const chunkBlobEntries = [];
|
|
362
387
|
|
|
363
388
|
for (let i = 0; i < chunks.length; i += this.merkleThreshold) {
|
|
364
389
|
const group = chunks.slice(i, i + this.merkleThreshold);
|
|
@@ -371,10 +396,6 @@ export default class CasService {
|
|
|
371
396
|
chunkCount: group.length,
|
|
372
397
|
startIndex: i,
|
|
373
398
|
});
|
|
374
|
-
|
|
375
|
-
for (const c of group) {
|
|
376
|
-
chunkBlobEntries.push(`100644 blob ${c.blob}\t${c.digest}`);
|
|
377
|
-
}
|
|
378
399
|
}
|
|
379
400
|
|
|
380
401
|
const rootManifestData = {
|
|
@@ -394,7 +415,7 @@ export default class CasService {
|
|
|
394
415
|
const treeEntries = [
|
|
395
416
|
`100644 blob ${rootOid}\tmanifest.${this.codec.extension}`,
|
|
396
417
|
...subManifestEntries,
|
|
397
|
-
...
|
|
418
|
+
...this._createChunkTreeEntries(chunks),
|
|
398
419
|
];
|
|
399
420
|
|
|
400
421
|
return await this.persistence.writeTree(treeEntries);
|