@spexcode/spec-eval 0.6.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.
@@ -0,0 +1,10 @@
1
+ export declare const MISS_BLOB = "miss original file";
2
+ export declare function cacheDir(): string;
3
+ export declare function putBlob(bytes: Buffer, dir?: string): string;
4
+ export declare function blobPath(sha: string, dir?: string): string;
5
+ export declare function hasBlob(sha: string | null, dir?: string): boolean;
6
+ export declare function resolveBlob(sha: string | null, dir?: string): string;
7
+ export declare function listBlobs(dir?: string): string[];
8
+ export declare function gc(keep: Set<string>, dir?: string): string[];
9
+ export declare function getBlob(sha: string | null, dir?: string): Buffer | null;
10
+ export declare function isStrayBlob(path: string): boolean;
package/dist/cache.js ADDED
@@ -0,0 +1,50 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, rmSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { gitCommonDir } from '@spexcode/spec-core';
5
+ export const MISS_BLOB = 'miss original file';
6
+ export function cacheDir() {
7
+ return join(gitCommonDir(), 'spexcode', 'evidence');
8
+ }
9
+ const BLOB_NAME = /^[0-9a-f]{64}$/;
10
+ export function putBlob(bytes, dir = cacheDir()) {
11
+ const sha = createHash('sha256').update(bytes).digest('hex');
12
+ mkdirSync(dir, { recursive: true });
13
+ const p = join(dir, sha);
14
+ if (!existsSync(p))
15
+ writeFileSync(p, bytes);
16
+ return sha;
17
+ }
18
+ export function blobPath(sha, dir = cacheDir()) {
19
+ return join(dir, sha);
20
+ }
21
+ export function hasBlob(sha, dir = cacheDir()) {
22
+ return !!sha && existsSync(blobPath(sha, dir));
23
+ }
24
+ export function resolveBlob(sha, dir = cacheDir()) {
25
+ if (!sha)
26
+ return '';
27
+ return hasBlob(sha, dir) ? blobPath(sha, dir) : MISS_BLOB;
28
+ }
29
+ export function listBlobs(dir = cacheDir()) {
30
+ if (!existsSync(dir))
31
+ return [];
32
+ return readdirSync(dir).filter((n) => BLOB_NAME.test(n)).sort();
33
+ }
34
+ export function gc(keep, dir = cacheDir()) {
35
+ const removed = [];
36
+ for (const name of listBlobs(dir)) {
37
+ if (keep.has(name))
38
+ continue;
39
+ rmSync(blobPath(name, dir));
40
+ removed.push(name);
41
+ }
42
+ return removed;
43
+ }
44
+ export function getBlob(sha, dir = cacheDir()) {
45
+ return hasBlob(sha, dir) ? readFileSync(blobPath(sha, dir)) : null;
46
+ }
47
+ export function isStrayBlob(path) {
48
+ const base = path.slice(path.lastIndexOf('/') + 1);
49
+ return BLOB_NAME.test(base) || path.includes('spexcode/evidence/') || path.includes('/yatsu-blobs/'); // dead-words-ok: archived cache dir name — a stray copy of the retired cache is still rejected
50
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { type EvalNode, type ScenarioTestReference } from './scenarios.js';
2
+ import { type Verdict } from './sidecar.js';
3
+ import { type EvalTimeline } from './evaltab.js';
4
+ export { isUiPath } from './ui-path.js';
5
+ export declare function nodeChanged(dirRel: string, codeFiles: readonly string[], changed: Set<string>, nodeDirs?: Iterable<string>): boolean;
6
+ declare function checkStaged(): number;
7
+ export declare function formatTimeline(tl: EvalTimeline): string;
8
+ export type ScenarioListRow = {
9
+ node: string;
10
+ scenario: string;
11
+ tags?: string[];
12
+ test?: ScenarioTestReference;
13
+ measured: boolean;
14
+ latest?: {
15
+ verdict?: Verdict;
16
+ ts: string;
17
+ };
18
+ };
19
+ export declare function scenarioListRows(nodes: EvalNode[], unmeasuredOnly?: boolean): ScenarioListRow[];
20
+ export declare function runEval(args: string[]): Promise<number>;
21
+ export { checkStaged };
22
+ export declare function runEvidence(args: string[]): Promise<number>;