@rig-c/review 2.4.3 → 2.4.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/parts-view.ts +26 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/review",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "type": "module",
5
5
  "description": "Local human rig inspection and structured feedback export",
6
6
  "license": "MIT",
package/src/parts-view.ts CHANGED
@@ -104,11 +104,14 @@ export async function insideRoot(root: string, path: string, code: string, what:
104
104
  return real;
105
105
  }
106
106
 
107
- async function hashFile(abs: string): Promise<LocalFile> {
108
- const bytes = await readFile(abs);
107
+ function hashBytes(abs: string, bytes: Buffer): LocalFile {
109
108
  return { abs, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') };
110
109
  }
111
110
 
111
+ async function hashFile(abs: string): Promise<LocalFile> {
112
+ return hashBytes(abs, await readFile(abs));
113
+ }
114
+
112
115
  /** A part name is a file stem under `parts/`: no separators, no traversal. */
113
116
  function partFileName(name: string): string {
114
117
  if (!name || name === '.' || name === '..' || /[/\\\x00-\x1f]/.test(name)) refuse('PARTS_NAME_INVALID', `part name ${JSON.stringify(name)} is not a file name under parts/`);
@@ -230,8 +233,13 @@ export function checkReadings(doc: unknown, names: ReadonlySet<string>): Produce
230
233
  return labelled ? rows : checkFlags(doc, names).map(f => ({...f, classification:'unclassified' as const, ...(f.kind === 'check' ? {line:JSON.stringify(f.entry)} : {})}));
231
234
  }
232
235
 
233
- async function readJson(abs: string, what: string): Promise<unknown> {
234
- try { return JSON.parse(await readFile(abs, 'utf8')); } catch (e) { return refuse('PARTS_FLAGS_MALFORMED', `${what}: ${e instanceof Error ? e.message : String(e)}`); }
236
+ function parseJson(bytes: Buffer, what: string): unknown {
237
+ try { return JSON.parse(bytes.toString('utf8')); } catch (e) { return refuse('PARTS_FLAGS_MALFORMED', `${what}: ${e instanceof Error ? e.message : String(e)}`); }
238
+ }
239
+
240
+ async function readJsonBytes(abs: string, what: string): Promise<{ bytes: Buffer; value: unknown }> {
241
+ try { const bytes = await readFile(abs); return { bytes, value: JSON.parse(bytes.toString('utf8')) }; }
242
+ catch (e) { return refuse('PARTS_FLAGS_MALFORMED', `${what}: ${e instanceof Error ? e.message : String(e)}`); }
235
243
  }
236
244
 
237
245
  /**
@@ -239,8 +247,9 @@ async function readJson(abs: string, what: string): Promise<unknown> {
239
247
  * writes `mesh_report.json` beside `parts.json` in `rig/`, and `check` writes `check/check.json` beside `rig/`.
240
248
  * `rigDir` is that `rig/` directory (parts mode) or null (atlas mode: explicit paths only, or `buildRoot`'s files).
241
249
  */
242
- async function producerFlags(rigDir: string | null, buildRoot: string | null, names: ReadonlySet<string>, options: PartsViewOptions): Promise<{ flags: ProducerFlag[]; readings: ProducerFlag[]; files: LocalFile[]; notes: string[] }> {
250
+ async function producerFlags(rigDir: string | null, buildRoot: string | null, names: ReadonlySet<string>, options: PartsViewOptions): Promise<{ flags: ProducerFlag[]; readings: ProducerFlag[]; files: LocalFile[]; notes: string[]; meshReport: unknown }> {
243
251
  const flags: ProducerFlag[] = [], readings: ProducerFlag[] = [], files: LocalFile[] = [], notes: string[] = [];
252
+ let meshReport: unknown = null;
244
253
  // 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.
245
254
  const pick = async (explicit: string | undefined, candidates: ([string, string] | null)[], what: string): Promise<string | null> => {
246
255
  if (explicit !== undefined) return realpath(resolve(explicit));
@@ -248,12 +257,12 @@ async function producerFlags(rigDir: string | null, buildRoot: string | null, na
248
257
  return found ? insideRoot(found[0], found[1], 'PARTS_FLAGS_OUTSIDE', what) : null;
249
258
  };
250
259
  const mesh = await pick(options.meshReport, [rigDir ? [rigDir, join(rigDir, 'mesh_report.json')] : null, buildRoot ? [buildRoot, join(buildRoot, 'rig', 'mesh_report.json')] : null], 'mesh_report.json');
251
- if (mesh) { files.push(await hashFile(mesh)); flags.push(...meshReportFlags(await readJson(mesh, 'mesh_report.json'), names)); }
260
+ if (mesh) { const bytes = await readFile(mesh); files.push(hashBytes(mesh, bytes)); meshReport = parseJson(bytes, 'mesh_report.json'); flags.push(...meshReportFlags(meshReport, names)); }
252
261
  else notes.push('mesh_report.json');
253
262
  const check = await pick(options.check, [rigDir ? [dirname(rigDir), join(dirname(rigDir), 'check', 'check.json')] : null, buildRoot ? [buildRoot, join(buildRoot, 'check', 'check.json')] : null], 'check/check.json');
254
- if (check) { files.push(await hashFile(check)); const doc = await readJson(check, 'check.json'); flags.push(...checkFlags(doc, names)); readings.push(...checkReadings(doc, names)); }
263
+ if (check) { const bytes = await readFile(check); files.push(hashBytes(check, bytes)); const doc = parseJson(bytes, 'check.json'); flags.push(...checkFlags(doc, names)); readings.push(...checkReadings(doc, names)); }
255
264
  else notes.push('check.json');
256
- return { flags, readings, files, notes };
265
+ return { flags, readings, files, notes, meshReport };
257
266
  }
258
267
 
259
268
  /** Exact attachment identity and UV-derived geometry; never reconstruct through weights. */
@@ -322,12 +331,13 @@ async function locateMeshRasters(rig: unknown, root: string, items: ViewItem[],
322
331
 
323
332
  async function loadPartsMode(root: string, options: PartsViewOptions): Promise<PartsViewPackage> {
324
333
  const partsJson = await insideRoot(root, join(root, 'parts.json'), 'PARTS_FILE_OUTSIDE', 'parts.json');
325
- const doc = record(await readJson(partsJson, 'parts.json'));
334
+ const { bytes: partsBytes, value: partsRaw } = await readJsonBytes(partsJson, 'parts.json');
335
+ const doc = record(partsRaw);
326
336
  const list = doc?.parts;
327
337
  if (!doc || !Array.isArray(list)) return refuse('PARTS_JSON_MALFORMED', 'parts.json has no parts[] array');
328
338
  const size = doc.rig_size;
329
339
  const rigSize: [number, number] | null = Array.isArray(size) && size.length === 2 && finite(size[0], 1) && finite(size[1], 1) ? [size[0], size[1]] : null;
330
- const items: ViewItem[] = [], imagePaths: string[] = [], files: LocalFile[] = [await hashFile(partsJson)];
340
+ const items: ViewItem[] = [], imagePaths: string[] = [], files: LocalFile[] = [hashBytes(partsJson, partsBytes)];
331
341
  const seen = new Set<string>();
332
342
  for (const [index, raw] of list.entries()) {
333
343
  const p = record(raw);
@@ -337,7 +347,7 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
337
347
  seen.add(part.name);
338
348
  const abs = join(root, 'parts', partFileName(part.name));
339
349
  if (!existsSync(abs)) refuse('PARTS_IMAGE_MISSING', `parts/${part.name}.png is named in parts.json and is not on disk`);
340
- // Hashed and served by its real path, so a link swapped after load cannot redirect what the page is shown.
350
+ // Resolved to its current real path inside root before hashing; full path-replacement pinning stays tracked in #479.
341
351
  const real = await insideRoot(root, abs, 'PARTS_IMAGE_OUTSIDE', `parts/${part.name}.png`);
342
352
  files.push(await hashFile(real));
343
353
  imagePaths.push(real);
@@ -368,7 +378,7 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
368
378
  assertOriginalPaintingSize(png!.width,png!.height,rigSize,doc.scale_rig_per_source);
369
379
  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);
370
380
  }
371
- const { flags, readings, files: flagFiles, notes } = await producerFlags(root, null, seen, options);
381
+ const { flags, readings, files: flagFiles, notes, meshReport } = await producerFlags(root, null, seen, options);
372
382
  const protectedPaths = [join(root, 'rig.json'), join(root, 'config.json'), join(root, 'review.json'), join(root, 'report.json')];
373
383
  if (basename(root) === 'rig') protectedPaths.push(...['parts.json', 'config.json', 'review.json', 'report.json'].map(name => join(dirname(root), name)));
374
384
  if (options.rig !== undefined) protectedPaths.push(resolve(options.rig));
@@ -381,7 +391,7 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
381
391
  let rig: unknown;
382
392
  try { rig = JSON.parse(rigBytes.toString('utf8')); }
383
393
  catch (e) { return refuse('PARTS_MESH_MALFORMED', `rig.json: ${e instanceof Error ? e.message : String(e)}`); }
384
- readPartMeshes(rig, items, report ? await readJson(report.abs, 'mesh_report.json') : null);
394
+ readPartMeshes(rig, items, report ? meshReport : null);
385
395
  await locateMeshRasters(rig, dirname(rigPath), items, imagePaths, files);
386
396
  // Bind exactly the bytes parsed above, even if the path is replaced during raster checks.
387
397
  files.push({ abs: rigPath, bytes: rigBytes.length, sha256: createHash('sha256').update(rigBytes).digest('hex') });
@@ -402,10 +412,11 @@ export async function loadPartsAtlas(p: ReviewPackage, options: PartsViewOptions
402
412
  const modelPath = p.manifest.model;
403
413
  if (!modelPath) return refuse('PARTS_VIEW_NO_ATLAS', `The inspected package holds no compiled model with pages`);
404
414
  const modelAbs = await safeFile(p.root, modelPath);
405
- const model = record(JSON.parse(await readFile(modelAbs, 'utf8')));
415
+ const modelBytes = await readFile(modelAbs);
416
+ const model = record(JSON.parse(modelBytes.toString('utf8')));
406
417
  const pagesRaw = model?.pages;
407
418
  if (!Array.isArray(pagesRaw)) return refuse('PARTS_VIEW_NO_ATLAS', `${modelPath} declares no pages`);
408
- const pages: ViewPage[] = [], pagePaths: string[] = [], items: ViewItem[] = [], files: LocalFile[] = [await hashFile(modelAbs)];
419
+ const pages: ViewPage[] = [], pagePaths: string[] = [], items: ViewItem[] = [], files: LocalFile[] = [hashBytes(modelAbs, modelBytes)];
409
420
  const names = new Set<string>();
410
421
  for (const raw of pagesRaw) {
411
422
  const page = record(raw);