rig-review 1.16.5 → 1.16.7
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/docs/REVIEW_PACKAGE.md +22 -3
- package/package.json +1 -1
- package/src/bones-check.ts +1 -1
- package/src/destination-directory.ts +28 -0
- package/src/environment-check.ts +1 -1
- package/src/open.ts +4 -3
- package/src/parts-view.ts +17 -7
- package/src/readings-run.ts +1 -1
- package/src/rebuild.ts +1 -1
- package/src/requirements-run.ts +1 -1
- package/src/state-dir.ts +16 -13
- package/src/strip-export.ts +6 -4
package/docs/REVIEW_PACKAGE.md
CHANGED
|
@@ -213,7 +213,7 @@ Every edit card states its edit as one config patch; review applies it to a scra
|
|
|
213
213
|
|
|
214
214
|
**`context.readings`.** Feedback written after a readings run carries the pairs of the last finished run: `{schema:"rig-review-readings/1", animation, requests[] (the readings as sent), environment, environmentPassed, builds:{inspected:<model sha256>, scratch:<build id>|null}, compiler:{package, version}, ticks:{inspected, scratch|null}}`; `null` when none ran. Absent and `null` stay valid; a present value must have this shape. The results themselves are not recorded: the AI receiving the review reruns the same `rigc render` readings on the named builds.
|
|
215
215
|
|
|
216
|
-
**Requirements (#113).** `GET /api/requirements` (single review) answers what the handoff's rig spec offers: `{status:"ready"|"unavailable", reason, bones[], slots[], meshes:{<slot>:[mesh attachment]}, slotBones:{<slot>:<bone>}, constraints:[{name, type:"ik"|"transform", bones[], drives[]}], animations:[{name, duration}], scratch:<build id>|null}`. `POST /api/requirements` (same-origin, capability, 64 KiB) takes exactly `{fps, build:"inspected"|"scratch", requirements:[1–64]}`, each requirement an object of at most 12 lower-case keys whose values are names, finite numbers or a `{bone, point}` / `{stage:[x, y]}` target; `may_fold` is refused. Malformed: HTTP 400 `REQUIREMENTS_REQUEST_INVALID`. Which kind, field, name or bar reads is the producer reader's to say. Outcomes (HTTP 200 `{status:"refused", error}`): `MODELING_HANDOFF_MISSING`, `MODELING_INPUT_UNAVAILABLE`, `REQUIREMENTS_NO_SCRATCH`, `MODELING_PRODUCER_NOT_INSTALLED`, `REQUIREMENTS_STATE_INSIDE_PACKAGE`, `REQUIREMENTS_BUSY`. Review writes `{spec:"spine-parts-requirements/1", fps, requirements}` (one-space JSON and a newline) as `requirements.json` in `<state>/requirements/<package hash>/<run id>/` and runs `rig-parts check --rig <the handoff rig, or the latest scratch build's rig spec> --out out --parts <handoff parts> --requirements requirements.json` there; the directory is removed after the run. The job (`GET /api/requirements/<id>`): `{schema:"rig-review-requirements/1", id, status:"running"|"checked"|"refused"|"failed", build, buildId, file:{sha256, size, text}, producer, exitCode, wallMs, rows:[{name, kind, animation, status, measured, least, greatest, worst:{frame, time, text}|null, reason, line}], summary, checkLine, refusals[] (`REQUIREMENTS_*` lines verbatim), problems[] (`CHECK_REQUIREMENT_MET` / `CHECK_REQUIREMENT_MEASURABLE` lines verbatim), error, lines[]}`; rows come from `check.json`'s `requirements` block, else from the printed `NAME: STATUS — …` lines.
|
|
216
|
+
**Requirements (#113).** `GET /api/requirements` (single review) answers what the handoff's rig spec offers: `{status:"ready"|"unavailable", reason, bones[], slots[], meshes:{<slot>:[mesh attachment]}, slotBones:{<slot>:<bone>}, constraints:[{name, type:"ik"|"transform", bones[], drives[]}], animations:[{name, duration}], scratch:<build id>|null}`. `POST /api/requirements` (same-origin, capability, 64 KiB) takes exactly `{fps, build:"inspected"|"scratch", requirements:[1–64]}`, each requirement an object of at most 12 lower-case keys whose values are names, finite numbers or a `{bone, point}` / `{stage:[x, y]}` target; `may_fold` is refused. Malformed: HTTP 400 `REQUIREMENTS_REQUEST_INVALID`. Which kind, field, name or bar reads is the producer reader's to say. Outcomes (HTTP 200 `{status:"refused", error}`): `MODELING_HANDOFF_MISSING`, `MODELING_INPUT_UNAVAILABLE`, `REQUIREMENTS_NO_SCRATCH`, `MODELING_PRODUCER_NOT_INSTALLED`, `REQUIREMENTS_STATE_INSIDE_PACKAGE`, `STATE_DIRECTORY_INVALID`, `REQUIREMENTS_BUSY`. Review writes `{spec:"spine-parts-requirements/1", fps, requirements}` (one-space JSON and a newline) as `requirements.json` in `<state>/requirements/<package hash>/<run id>/` and runs `rig-parts check --rig <the handoff rig, or the latest scratch build's rig spec> --out out --parts <handoff parts> --requirements requirements.json` there; the directory is removed after the run. The job (`GET /api/requirements/<id>`): `{schema:"rig-review-requirements/1", id, status:"running"|"checked"|"refused"|"failed", build, buildId, file:{sha256, size, text}, producer, exitCode, wallMs, rows:[{name, kind, animation, status, measured, least, greatest, worst:{frame, time, text}|null, reason, line}], summary, checkLine, refusals[] (`REQUIREMENTS_*` lines verbatim), problems[] (`CHECK_REQUIREMENT_MET` / `CHECK_REQUIREMENT_MEASURABLE` lines verbatim), error, lines[]}`; rows come from `check.json`'s `requirements` block, else from the printed `NAME: STATUS — …` lines.
|
|
217
217
|
|
|
218
218
|
**Self-targeted requirements (#142).** The panel refuses before Add, as `REQUIREMENTS_SELF_TARGET`, a `contact` whose target is its own bone and point and an `aim` whose target bone is the aimed bone: both measure 0 in every frame and the producer reports them as PASS (its own refusal is rig-c/parts#540). A bone's tip against its own origin is not refused; it measures the bone's length. A fresh contact or aim form proposes a target bone other than the subject (the next bone in rig order).
|
|
219
219
|
|
|
@@ -400,11 +400,11 @@ PNG responses are `image/png` attachment downloads; JSON responses are `applicat
|
|
|
400
400
|
|
|
401
401
|
Only selected-basis report `frameTimes` supplies strip times. A matching report animation is required. Uniform metadata remains supported by inspection transport but does not become a strip sampling substitute. A clockless JSON group keeps its inclusive frames and `time:null`; clockless PNG refuses with `Report has no frameTimes — regenerate with pose 0.30.0 or later`. A compare A without a clock remains renderable from B's explicit times and has no inferred A frame label. Each actual reference PTS is selected nearest to the request (ties earlier), and all rig rows use that same PTS. Requested/decoded times outside the common clip/video domain refuse, without a per-source clamp.
|
|
402
402
|
|
|
403
|
-
Each interval has its own source-row grid; overlapping groups preserve their feedback ids and repeated frames. Source packages and reference are checked before and after export, including exact model/page/motion bytes through existing package hashes. The PNG footer includes full rig/motion hashes (null stays absent), revisions, viewer/runtime and actual renderer versions. Exports are derived evidence, never a new source or approval. CLI destinations and `.json` sidecars must be new files outside
|
|
403
|
+
Each interval has its own source-row grid; overlapping groups preserve their feedback ids and repeated frames. Source packages and reference are checked before and after export, including exact model/page/motion bytes through existing package hashes. The PNG footer includes full rig/motion hashes (null stays absent), revisions, viewer/runtime and actual renderer versions. Exports are derived evidence, never a new source or approval. CLI destinations and `.json` sidecars must be new files. An existing output parent may be reached through a symlink, including macOS `/var`, if the physical destination is outside every source root. An existing destination entry, including a dangling symlink, is refused. Downloads have no arbitrary filesystem destination parameter.
|
|
404
404
|
|
|
405
405
|
The pure layout reserves a maximum `footerHeight` budget for complete provenance. The native renderer wraps the actual footer text before allocation and uses only that measured height; `rendering.width/height` records the actual PNG extent. Unsupported RGB/dark tint refuses by name (`STRIP_UNSUPPORTED_TINT`) rather than claiming Canvas2D pixel parity for features its published renderer omits. Labels and footer use concrete font-family lists, never a generic family (Node Canvas resolves those to the machine's first family); when no family of the mono or sans list is installed, rendering refuses `STRIP_FONT`, naming both lists, before any reference probe or drawing.
|
|
406
406
|
|
|
407
|
-
A strip plan with one clock basis reports `plan.basis:"single"|"a"|"b"`. A comparison batch containing both sides reports `plan.basis:"mixed"`; each group still carries its own `basis` and its own report-derived sample times. Consumers must use the group basis for a mixed plan rather than treating the first group as a batch-wide clock. The selected basis row labels requested producer frames/times; actual PTS and independently calculated actual frames remain separate rendering metadata. Output containment
|
|
407
|
+
A strip plan with one clock basis reports `plan.basis:"single"|"a"|"b"`. A comparison batch containing both sides reports `plan.basis:"mixed"`; each group still carries its own `basis` and its own report-derived sample times. Consumers must use the group basis for a mixed plan rather than treating the first group as a batch-wide clock. The selected basis row labels requested producer frames/times; actual PTS and independently calculated actual frames remain separate rendering metadata. Output containment uses native platform separators, including Windows drive and UNC paths.
|
|
408
408
|
|
|
409
409
|
## Open-managed handoff and explicit single reference
|
|
410
410
|
|
|
@@ -499,6 +499,25 @@ applies the same canonical check and refuses with its own `*_STATE_INSIDE_PACKAG
|
|
|
499
499
|
code naming the folder. No package manifest, source video, motion or compiled
|
|
500
500
|
model is written by open. There is no browser launch or new LAN exposure.
|
|
501
501
|
|
|
502
|
+
Review resolves the existing directory prefix of a state path or explicit
|
|
503
|
+
parts verdict parent. An `ENOENT` suffix can be created when the command needs
|
|
504
|
+
it. A regular file in the directory path (`ENOTDIR`) or a symlink loop
|
|
505
|
+
(`ELOOP`) stops resolution. Parts verdict resolution preserves the original
|
|
506
|
+
output filename, and protected input collisions still refuse by name.
|
|
507
|
+
State guards return `STATE_DIRECTORY_INVALID` through the existing HTTP 200
|
|
508
|
+
refusal response on guarded routes.
|
|
509
|
+
|
|
510
|
+
| Input | Previous behavior | Current behavior |
|
|
511
|
+
| --- | --- | --- |
|
|
512
|
+
| Strip destination under a symlink to an existing directory outside the source roots | `strip.output` refused the symlink with the `without symlinks` suffix | Writes to the physical directory with the original filename |
|
|
513
|
+
| Strip destination with a missing parent | Raw `ENOENT` | `strip.output: parent must be an existing directory` |
|
|
514
|
+
| Strip destination with a loop in its parent path | Raw `ELOOP` if raised during lookup, or the earlier `without symlinks` refusal | `strip.output: parent must be an existing directory` |
|
|
515
|
+
| `open` state path through a regular file or loop | Raw `ENOTDIR` or `ELOOP` | `OPEN_STATE_INVALID` |
|
|
516
|
+
| `control` state path through a regular file or loop | Raw `ENOTDIR` or `ELOOP` | `CONTROL_STATE` |
|
|
517
|
+
| State guard sees a regular file inside the package with a requested suffix | `*_STATE_INSIDE_PACKAGE` | `STATE_DIRECTORY_INVALID` |
|
|
518
|
+
| State guard sees a symlink loop | Raw `ELOOP` | `STATE_DIRECTORY_INVALID` |
|
|
519
|
+
| Parts or atlas verdict parent through a regular file or loop | Raw `ENOTDIR` or `ELOOP` | `PARTS_VERDICT_DESTINATION_INVALID` |
|
|
520
|
+
|
|
502
521
|
The printed feedback retrieval command uses POSIX shell quoting for literal path
|
|
503
522
|
arguments. It is not a PowerShell or cmd.exe command string.
|
|
504
523
|
|
package/package.json
CHANGED
package/src/bones-check.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function createBonesCheck(p: ReviewPackage, options: { stateDir: string;
|
|
|
61
61
|
let running = false;
|
|
62
62
|
async function run(input: unknown): Promise<BonesCheckResult> {
|
|
63
63
|
const { ops, configHash } = parseBonesCheck(input);
|
|
64
|
-
assertStateDirOutside(options.stateDir, p, message => new RebuildError('REBUILD_STATE_INSIDE_PACKAGE', message));
|
|
64
|
+
assertStateDirOutside(options.stateDir, p, (message, code) => new RebuildError(code ?? 'REBUILD_STATE_INSIDE_PACKAGE', message));
|
|
65
65
|
await options.unchanged();
|
|
66
66
|
const inputs = await producerInputs(p.handoff, p.handoffReason);
|
|
67
67
|
const original = JSON.parse(inputs.configText) as JsonValue;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export class DestinationDirectoryError extends Error {}
|
|
5
|
+
|
|
6
|
+
/** Resolve directory aliases and keep an ENOENT suffix only when the caller can create it. */
|
|
7
|
+
export function destinationDirectory(path: string, refusal: string, allowMissing = true): string {
|
|
8
|
+
const suffix: string[] = [];
|
|
9
|
+
for (let current = resolve(path); ; current = dirname(current)) {
|
|
10
|
+
let physical: string;
|
|
11
|
+
try {
|
|
12
|
+
physical = realpathSync(current);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
15
|
+
if (code === 'ENOENT' && allowMissing && dirname(current) !== current) {
|
|
16
|
+
suffix.unshift(basename(current));
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (code === 'ENOENT' || code === 'ENOTDIR' || code === 'ELOOP') {
|
|
20
|
+
throw new DestinationDirectoryError(refusal, { cause: error });
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
// Some runtimes report ENOENT for a descendant of a regular file.
|
|
25
|
+
if (!statSync(physical).isDirectory()) throw new DestinationDirectoryError(refusal);
|
|
26
|
+
return join(physical, ...suffix);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/environment-check.ts
CHANGED
|
@@ -79,7 +79,7 @@ export function createEnvironmentCheck(p: ReviewPackage, options: EnvironmentChe
|
|
|
79
79
|
let running: string | null = null;
|
|
80
80
|
const snapshot = (job: EnvironmentCheckJob): EnvironmentCheckJob => JSON.parse(JSON.stringify(job)) as EnvironmentCheckJob;
|
|
81
81
|
function assertStateOutside(): void {
|
|
82
|
-
assertStateDirOutside(options.stateDir, p, message => new EnvironmentCheckError('ENVIRONMENT_CHECK_STATE_INSIDE_PACKAGE', message));
|
|
82
|
+
assertStateDirOutside(options.stateDir, p, (message, code) => new EnvironmentCheckError(code ?? 'ENVIRONMENT_CHECK_STATE_INSIDE_PACKAGE', message));
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
async function execute(job: EnvironmentCheckJob, dir: string, bin: string, rig: string, parts: string, text: string): Promise<void> {
|
package/src/open.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {ensureFront,frontPort} from './front.ts';
|
|
|
19
19
|
import {playPackagePath} from './versions.ts';
|
|
20
20
|
import {HandoffError,HANDOFF_FLAGS,isBuildRoot,type HandoffFlags,type HandoffRecord} from './handoff.ts';
|
|
21
21
|
import {stateDirInside,stateRoots} from './state-dir.ts';
|
|
22
|
+
import {destinationDirectory} from './destination-directory.ts';
|
|
22
23
|
import {DEFAULT_UNOPENED_TIMEOUT_MS} from './live-lifecycle.ts';
|
|
23
24
|
import {verifyCompiledModel} from './strip-render.ts';
|
|
24
25
|
import {verifyHandoffReadiness} from './rebuild.ts';
|
|
@@ -82,7 +83,6 @@ async function claimOwner(claim:string):Promise<{file:string;pid:number;nonce:st
|
|
|
82
83
|
}
|
|
83
84
|
async function removeClaimFile(claim:string,owner:{file:string;nonce:string}){try{const current=await smallJson(owner.file) as {nonce?:string};if(current.nonce!==owner.nonce)return;await unlink(owner.file);await rmdir(claim);}catch(e){if(!['ENOENT','ENOTEMPTY','EEXIST'].includes((e as NodeJS.ErrnoException).code??''))throw e;}}
|
|
84
85
|
export async function releaseClaim(claim:string,nonce:string){await removeClaimFile(claim,{file:join(claim,`owner.${nonce}.json`),nonce});}
|
|
85
|
-
async function canonicalDestination(path:string):Promise<string>{try{return await realpath(path);}catch(e){if((e as NodeJS.ErrnoException).code!=='ENOENT')throw e;const parent=dirname(path);if(parent===path)throw e;return join(await canonicalDestination(parent),basename(path));}}
|
|
86
86
|
/** Single-owner startup: publish a populated claim directory atomically (no live owner ever exposes an empty
|
|
87
87
|
* claim; unique owner filenames make stale cleanup safe after replacement). A ready reuse wins while waiting. */
|
|
88
88
|
export async function acquireClaim<T>(control:string,name:string,nonce:string,reuse:()=>Promise<T|null>,deadline:number,busy:string):Promise<{row:T}|{claim:string}>{
|
|
@@ -132,7 +132,7 @@ export async function openReview(inputs:OpenInputs,options:{stateDir?:string;idl
|
|
|
132
132
|
let p:OpenPackage;try{p=await loadOpenPackage(inputs);}catch(error){throw await openRefusal(error,inputs);}
|
|
133
133
|
const fingerprint=await openFingerprint(),key=openKey(p,fingerprint);
|
|
134
134
|
// #187: canonical (symlinks and ancestors resolved) and outside every supplied folder: the package, the build root a check package belongs to, the handoff root.
|
|
135
|
-
const stateDir=
|
|
135
|
+
const stateDir=destinationDirectory(options.stateDir??defaultStateDir(),'OPEN_STATE_INVALID: the state directory path has a non-directory component or a symlink loop'),roots=p.mode==='single'?stateRoots(p.p):[...stateRoots(p.p.a),...stateRoots(p.p.b)];
|
|
136
136
|
if(p.mode==='single'&&p.joined&&stateDirInside(stateDir,[{kind:'package',path:p.joined.opened.root}]))throw new Error('OPEN_STATE_INSIDE_PACKAGE: review state must be outside the joined project');
|
|
137
137
|
const inside=stateDirInside(stateDir,roots);if(inside)throw new Error(`OPEN_STATE_INSIDE_PACKAGE ${inside.kind}: the review state directory must be outside input packages; it is inside the ${inside.kind}; set RIG_REVIEW_STATE_DIR outside it`);
|
|
138
138
|
await verifyOpenLoad(p,viewOnly,options.cwd);
|
|
@@ -177,7 +177,8 @@ export async function runOpenWorker(requestPath:string):Promise<void>{
|
|
|
177
177
|
/** Read/control an already running, explicitly opted-in exact binding. Never starts a worker. */
|
|
178
178
|
export async function controlReview(inputs:OpenInputs,commandOptions:{pageId?:string;expectedRevision?:number;requestId?:string;command?:ControlCommand;waitMs?:number;stateDir?:string}={}):Promise<unknown>{
|
|
179
179
|
const wait=commandOptions.waitMs??10000;if(!Number.isSafeInteger(wait)||wait<0||wait>30000)throw new Error('CONTROL_WAIT: expected integer 0..30000');
|
|
180
|
-
const p=await loadOpenPackage({...inputs,control:true}),fingerprint=await openFingerprint(),key=openKey(p,fingerprint)
|
|
180
|
+
const p=await loadOpenPackage({...inputs,control:true}),fingerprint=await openFingerprint(),key=openKey(p,fingerprint);
|
|
181
|
+
const stateDir=destinationDirectory(commandOptions.stateDir??defaultStateDir(),'CONTROL_STATE: the state directory path has a non-directory component or a symlink loop');
|
|
181
182
|
const controlDir=join(stateDir,'open');
|
|
182
183
|
try{if((await lstat(controlDir)).isSymbolicLink())throw new Error('CONTROL_STATE: control directory cannot be a symlink');}catch(error){if((error as NodeJS.ErrnoException).code==='ENOENT')throw new Error('CONTROL_INSTANCE_UNAVAILABLE: open the exact inputs once with --control');throw error;}
|
|
183
184
|
const file=join(controlDir,key+'.json');try{const info=await lstat(file);if(!info.isFile()||(info.mode&0o077)!==0)throw new Error('CONTROL_STATE: owner-only regular capability record required');}catch(error){if((error as NodeJS.ErrnoException).code==='ENOENT')throw new Error('CONTROL_INSTANCE_UNAVAILABLE: open the exact inputs once with --control');throw error;}
|
package/src/parts-view.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { mkdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/
|
|
|
25
25
|
import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
26
26
|
import { PNG } from 'pngjs';
|
|
27
27
|
import { loadReview, safeFile, packagePath, type ReviewPackage } from './manifest.ts';
|
|
28
|
+
import { destinationDirectory } from './destination-directory.ts';
|
|
28
29
|
|
|
29
30
|
export const PARTS_VERDICT_SCHEMA = 'rig-review-parts-verdict/2';
|
|
30
31
|
export const PARTS_VERDICT_FILE = 'parts-review.json';
|
|
@@ -99,7 +100,7 @@ const refuse = (code: string, message: string): never => { throw new Error(`${co
|
|
|
99
100
|
export async function insideRoot(root: string, path: string, code: string, what: string): Promise<string> {
|
|
100
101
|
const realRoot = await realpath(root), real = await realpath(path);
|
|
101
102
|
const rel = relative(realRoot, real);
|
|
102
|
-
if (!rel || rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) refuse(code, `${what} resolves outside ${basename(realRoot)}
|
|
103
|
+
if (!rel || rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) refuse(code, `${what} resolves outside ${basename(realRoot)}/`);
|
|
103
104
|
return real;
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -128,6 +129,14 @@ function relativeTo(dir: string, abs: string): string {
|
|
|
128
129
|
return sep === '/' ? rel : rel.split(sep).join('/');
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
/** Match canonical input paths, resolving only the destination's parent. Missing
|
|
133
|
+
* directories retain their suffix; the output leaf is never followed through a symlink. */
|
|
134
|
+
function verdictDestination(path: string): string {
|
|
135
|
+
const absolute = resolve(path);
|
|
136
|
+
const parent = destinationDirectory(dirname(absolute), 'PARTS_VERDICT_DESTINATION_INVALID: the verdict parent path has a non-directory component or a symlink loop');
|
|
137
|
+
return join(parent, basename(absolute));
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
/** Faint islands (rig-parts #326) from `mesh_report.json` rows, on the parts the view holds. */
|
|
132
141
|
export function meshReportFlags(rows: unknown, names: ReadonlySet<string>): ProducerFlag[] {
|
|
133
142
|
if (!Array.isArray(rows)) refuse('PARTS_FLAGS_MALFORMED', 'mesh_report.json is not an array of rows');
|
|
@@ -234,7 +243,7 @@ async function producerFlags(rigDir: string | null, buildRoot: string | null, na
|
|
|
234
243
|
const flags: ProducerFlag[] = [], readings: ProducerFlag[] = [], files: LocalFile[] = [], notes: string[] = [];
|
|
235
244
|
// A discovered file must resolve inside the directory it was discovered in; a path given on the command line is the user's own choice.
|
|
236
245
|
const pick = async (explicit: string | undefined, candidates: ([string, string] | null)[], what: string): Promise<string | null> => {
|
|
237
|
-
if (explicit !== undefined) return resolve(explicit);
|
|
246
|
+
if (explicit !== undefined) return realpath(resolve(explicit));
|
|
238
247
|
const found = candidates.find((c): c is [string, string] => !!c && existsSync(c[1]));
|
|
239
248
|
return found ? insideRoot(found[0], found[1], 'PARTS_FLAGS_OUTSIDE', what) : null;
|
|
240
249
|
};
|
|
@@ -352,8 +361,9 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
|
|
|
352
361
|
paintingInRig={abs,declaredPath,bytes:bytes.length,sha256,width:png!.width,height:png!.height};files.push(paintingInRig);
|
|
353
362
|
}
|
|
354
363
|
let painting:PartsViewPackage['painting'];if(options.painting){
|
|
355
|
-
|
|
356
|
-
|
|
364
|
+
// Both paths are physical: a user-designated alias to an inside file is valid,
|
|
365
|
+
// while a link reaching outside is refused before any painting bytes are read.
|
|
366
|
+
let abs:string,bytes:Buffer;try{abs=await insideRoot(root,resolve(options.painting),'PARTS_PAINTING_OUTSIDE','painting');packagePath(relative(root,abs).split(sep).join('/'),'painting');bytes=await readFile(abs);}catch(error){if(error instanceof Error&&error.message.startsWith('PARTS_PAINTING_OUTSIDE:'))throw error;refuse('PARTS_PAINTING_UNAVAILABLE','painting must be a readable portable package PNG');}
|
|
357
367
|
let png:PNG;try{png=PNG.sync.read(bytes!);}catch{refuse('PARTS_PAINTING_PNG','painting must be a valid PNG');}
|
|
358
368
|
assertOriginalPaintingSize(png!.width,png!.height,rigSize,doc.scale_rig_per_source);
|
|
359
369
|
const file={abs:abs!,bytes:bytes!.length,sha256:createHash('sha256').update(bytes!).digest('hex')};painting={...file,width:png!.width,height:png!.height};files.push(file);
|
|
@@ -362,9 +372,9 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
|
|
|
362
372
|
const protectedPaths = [join(root, 'rig.json'), join(root, 'config.json'), join(root, 'review.json'), join(root, 'report.json')];
|
|
363
373
|
if (basename(root) === 'rig') protectedPaths.push(...['parts.json', 'config.json', 'review.json', 'report.json'].map(name => join(dirname(root), name)));
|
|
364
374
|
if (options.rig !== undefined) protectedPaths.push(resolve(options.rig));
|
|
365
|
-
const verdictPath = options.verdict ?
|
|
375
|
+
const verdictPath = options.verdict ? verdictDestination(options.verdict) : join(root, PARTS_VERDICT_FILE);
|
|
366
376
|
await assertVerdictDestination({ files, flagFiles, protectedPaths, verdictPath });
|
|
367
|
-
const rigPath = options.rig !== undefined ? resolve(options.rig) : existsSync(join(root, 'rig.json')) ? await insideRoot(root, join(root, 'rig.json'), 'PARTS_MESH_OUTSIDE', 'rig.json') : null;
|
|
377
|
+
const rigPath = options.rig !== undefined ? await realpath(resolve(options.rig)) : existsSync(join(root, 'rig.json')) ? await insideRoot(root, join(root, 'rig.json'), 'PARTS_MESH_OUTSIDE', 'rig.json') : null;
|
|
368
378
|
if (rigPath) {
|
|
369
379
|
const report = notes.includes('mesh_report.json') ? undefined : flagFiles[0];
|
|
370
380
|
const rigBytes = await readFile(rigPath);
|
|
@@ -419,7 +429,7 @@ export async function loadPartsAtlas(p: ReviewPackage, options: PartsViewOptions
|
|
|
419
429
|
protectedPaths.push(...['rig.json', 'config.json', 'report.json', 'review.json'].map(name => join(p.root, name)));
|
|
420
430
|
if (p.handoff) protectedPaths.push(...p.handoff.record.files.map(file => resolve(p.root, file.path)));
|
|
421
431
|
if (buildRoot) protectedPaths.push(...['parts.json', 'config.json', 'rig/rig.json', 'rig/parts.json'].map(name => join(buildRoot, name)));
|
|
422
|
-
return { mode: 'atlas', root: p.root, title: p.manifest.title, rigSize: null, items, pages, flags, readings, files, flagFiles, flagNotes: notes, protectedPaths, verdictPath: options.verdict ?
|
|
432
|
+
return { mode: 'atlas', root: p.root, title: p.manifest.title, rigSize: null, items, pages, flags, readings, files, flagFiles, flagNotes: notes, protectedPaths, verdictPath: options.verdict ? verdictDestination(options.verdict) : join(dirname(modelAbs), PARTS_VERDICT_FILE), imagePaths: [], pagePaths };
|
|
423
433
|
}
|
|
424
434
|
|
|
425
435
|
/**
|
package/src/readings-run.ts
CHANGED
|
@@ -68,7 +68,7 @@ export function createReadings(p: ReviewPackage, options: ReadingsOptions) {
|
|
|
68
68
|
let running: string | null = null;
|
|
69
69
|
const snapshot = (job: ReadingsJob): ReadingsJob => JSON.parse(JSON.stringify(job)) as ReadingsJob;
|
|
70
70
|
function assertStateOutside(): void {
|
|
71
|
-
assertStateDirOutside(options.stateDir, p, message => new ReadingsError('READINGS_STATE_INSIDE_PACKAGE', message));
|
|
71
|
+
assertStateDirOutside(options.stateDir, p, (message, code) => new ReadingsError(code ?? 'READINGS_STATE_INSIDE_PACKAGE', message));
|
|
72
72
|
}
|
|
73
73
|
/** Whether this rigc's `render --help` lists `--environment`, asked once per compiler. */
|
|
74
74
|
async function environmentFlag(compiler: InstalledTool): Promise<boolean> {
|
package/src/rebuild.ts
CHANGED
|
@@ -772,7 +772,7 @@ export function createRebuilds(p: ReviewPackage, options: RebuildOptions) {
|
|
|
772
772
|
|
|
773
773
|
/** The state directory may not sit inside the package or the handoff's root (the parent of an opened out/). */
|
|
774
774
|
function assertStateOutside(): void {
|
|
775
|
-
assertStateDirOutside(options.stateDir, p, message => new RebuildError('REBUILD_STATE_INSIDE_PACKAGE', message));
|
|
775
|
+
assertStateDirOutside(options.stateDir, p, (message, code) => new RebuildError(code ?? 'REBUILD_STATE_INSIDE_PACKAGE', message));
|
|
776
776
|
}
|
|
777
777
|
/** Once per session: the first time the handoff and the producer both resolve, the baseline starts (or is reused). */
|
|
778
778
|
let baseline: BaselineResult | null = null, baselineRun: Promise<BaselineResult> | null = null;
|
package/src/requirements-run.ts
CHANGED
|
@@ -90,7 +90,7 @@ export function createRequirementsCheck(p: ReviewPackage, options: RequirementsO
|
|
|
90
90
|
let running: string | null = null;
|
|
91
91
|
const snapshot = (job: RequirementsJob): RequirementsJob => JSON.parse(JSON.stringify(job)) as RequirementsJob;
|
|
92
92
|
function assertStateOutside(): void {
|
|
93
|
-
assertStateDirOutside(options.stateDir, p, message => new RequirementsError('REQUIREMENTS_STATE_INSIDE_PACKAGE', message));
|
|
93
|
+
assertStateDirOutside(options.stateDir, p, (message, code) => new RequirementsError(code ?? 'REQUIREMENTS_STATE_INSIDE_PACKAGE', message));
|
|
94
94
|
}
|
|
95
95
|
const asRequirements = (e: unknown): never => { if (e instanceof RebuildError) throw new RequirementsError(e.code, e.message.slice(e.code.length + 2)); throw e; };
|
|
96
96
|
|
package/src/state-dir.ts
CHANGED
|
@@ -5,23 +5,20 @@
|
|
|
5
5
|
* inside the rig-parts build root the check package belongs to (opening `out` redirects the package to `out/check`;
|
|
6
6
|
* the build is still the supplied folder), the package root, or the producer handoff's root.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
9
|
+
import { destinationDirectory, DestinationDirectoryError } from './destination-directory.ts';
|
|
10
10
|
|
|
11
11
|
export type StateRootKind = 'build root' | 'package' | 'handoff root';
|
|
12
12
|
export interface StateRoot { kind: StateRootKind; path: string }
|
|
13
13
|
/** The fields of a loaded package that name supplied folders. */
|
|
14
14
|
export interface StateRootsSource { root: string; buildRoot?: string; handoff?: { root: string } | null }
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const invalidCode = 'STATE_DIRECTORY_INVALID';
|
|
17
|
+
const invalidMessage = 'the state directory path has a non-directory component or a symlink loop';
|
|
17
18
|
|
|
18
|
-
/**
|
|
19
|
+
/** Resolve the existing directory prefix and keep any missing suffix. */
|
|
19
20
|
export function canonicalStatePath(path: string): string {
|
|
20
|
-
|
|
21
|
-
for (let current = absolute; ; current = dirname(current)) {
|
|
22
|
-
try { const real = realpathSync(current); return rest.length ? join(real, ...rest.reverse()) : real; }
|
|
23
|
-
catch (e) { if (!missing(e) || dirname(current) === current) throw e; rest.push(basename(current)); }
|
|
24
|
-
}
|
|
21
|
+
return destinationDirectory(path, `${invalidCode}: ${invalidMessage}`);
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
/** The supplied folders of one package, innermost first (a refusal names the first that holds the state). */
|
|
@@ -41,8 +38,14 @@ export function stateDirInside(stateDir: string, roots: readonly StateRoot[]): S
|
|
|
41
38
|
/** The refusal text after the code: which supplied folder holds the state directory. */
|
|
42
39
|
export const stateInsideMessage = (root: StateRoot) => `the review state directory is inside the inspected ${root.kind}; set RIG_REVIEW_STATE_DIR outside it`;
|
|
43
40
|
|
|
44
|
-
/**
|
|
45
|
-
export function assertStateOutside(stateDir: string, p: StateRootsSource, make: (message: string,
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
/** Use the caller's refusal type for invalid state paths and paths inside supplied folders. */
|
|
42
|
+
export function assertStateOutside(stateDir: string, p: StateRootsSource, make: (message: string, code?: typeof invalidCode) => Error): void {
|
|
43
|
+
let root: StateRoot | null;
|
|
44
|
+
try {
|
|
45
|
+
root = stateDirInside(stateDir, stateRoots(p));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error instanceof DestinationDirectoryError) throw make(invalidMessage, invalidCode);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
if (root) throw make(stateInsideMessage(root));
|
|
48
51
|
}
|
package/src/strip-export.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { realpath, stat, lstat, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { createReadStream } from 'node:fs';
|
|
4
|
-
import { basename, dirname, isAbsolute, relative, resolve, parse, sep, type posix } from 'node:path';
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, parse, sep, type posix } from 'node:path';
|
|
5
|
+
import { destinationDirectory } from './destination-directory.ts';
|
|
5
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
6
7
|
import { safeFile, type ReviewPackage } from './manifest.ts';
|
|
7
8
|
import {assertReviewUnchanged,selectedReference,safeSelectedReference,packageSourceHash} from './reference.ts';
|
|
@@ -55,10 +56,11 @@ export function stripParentPaths(target:string,paths:Pick<typeof posix,'relative
|
|
|
55
56
|
const base=paths.parse(target).root,parts=paths.relative(base,paths.dirname(target)).split(paths.sep).filter(Boolean),parents:string[]=[];let cursor=base;
|
|
56
57
|
for(const part of parts){cursor=paths.resolve(cursor,part);parents.push(cursor);}return parents;
|
|
57
58
|
}
|
|
58
|
-
/**
|
|
59
|
+
/** Resolve the parent, preserving the output filename for the existence check and exclusive write. */
|
|
59
60
|
export async function validateStripOutput(output:string,roots:string[]):Promise<string>{
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
const absolute=resolve(output);
|
|
62
|
+
const parent=destinationDirectory(dirname(absolute),'strip.output: parent must be an existing directory',false);
|
|
63
|
+
const target=join(parent,basename(absolute));
|
|
62
64
|
for(const root of roots)if(stripPathIsInside(await realpath(root),target))throw new Error('strip.output: derived files must be outside every source package');
|
|
63
65
|
try{await lstat(target);throw new Error('strip.output: destination already exists');}catch(e){if((e as NodeJS.ErrnoException).code!=='ENOENT')throw e;}
|
|
64
66
|
return target;
|