Skip to content

Read the manifest in stampManifest through JsonFields, without a cast - #264

Merged
rostislavrotaru merged 2 commits into
mainfrom
dev5/195-stamp-manifest-json
Nov 30, 2026
Merged

rostislavrotaru merged 2 commits into
mainfrom
dev5/195-stamp-manifest-json

Conversation

@rostislavrotaru

@rostislavrotaru rostislavrotaru commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #195.

What changes

scripts/build.ts's stampManifest reads the package manifest through JsonFields.parse, as the file's other JSON reads do, instead of casting JSON.parse(text) to Readonly<Record<string, unknown>>. It copies every field of the manifest's own, from JsonFields.fields(), but the workspace ones into a Map, then sets version and, when there is a commit, gitHead. A Map keeps an existing key's place when it is set again, as the object spread did, so the stamped manifest is the same text as before.

JsonFields gains fields(), a ReadonlyMap<string, unknown> of the object's own fields in their order, built from Object.entries, so no prototype name such as constructor reads as a field. Its older reads still use Reflect.get and Reflect.has; #265 moves them.

A manifest that isn't JSON, or isn't a JSON object, now fails with JsonFields' message ("package.json is not JSON.") instead of a bare SyntaxError.

Earlier work

None: this is a change to the build script only.

Checks

  • On Linux, Mac and Windows: npm run build passes, which type-checks the scripts. A comparison script then stamped the source package.json the way main's stampManifest did and compared it with the built package's package.json. On all three systems the two are the same text, 3561 characters with version and gitHead, and with none of scripts, devDependencies or allowScripts.
  • No specs cover scripts/build.ts, so there is no new test to fail without the change; the comparison above is the check.

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
@rostislavrotaru rostislavrotaru self-assigned this Nov 30, 2026
@rostislavrotaru

Copy link
Copy Markdown
Contributor Author

Ready at 9371bd8, #195.

Changed: stampManifest reads the manifest through JsonFields.parse, with no cast; JsonFields gains field(name), which returns a field's value as unknown.
Checks: Linux, Mac and Windows: npm run build (which type-checks the scripts) passes, and the built package.json is the same text main's stamping gives. No specs cover scripts/build.ts. CI green at 9371bd8. 1 behind main (#262), no conflict.
Not checked: nothing open.

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru
rostislavrotaru marked this pull request as ready for review November 30, 2026 04:02

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: #264 at 9371bd8
Verdict: Changes needed
Findings: 1 Should fix, 0 Low, as line comments

Agent: REVIEW2 (reviewer)
Agent-Model: Anthropic Opus 5.5, High

…eflect.get

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: #264 at f930559
Verdict: Approve
Findings: 0 Should fix, 0 Low, as line comments
Why it's right: fields() is built from Object.entries and stampManifest iterates it, so the Reflect.get path is gone; the macOS x64 job's rise is within main's last ten runs for a script-only change.

Agent: LEAD (lead)
Agent-Model: Anthropic Opus 5.5, High

@rostislavrotaru
rostislavrotaru merged commit 2c26384 into main Nov 30, 2026
19 checks passed
@rostislavrotaru
rostislavrotaru deleted the dev5/195-stamp-manifest-json branch November 30, 2026 04:24
rostislavrotaru added a commit that referenced this pull request Nov 30, 2026
Closes #265

`JsonFields` reads every field through `fields()`, the map of the
object's own fields that #264 added, instead of `Reflect.get` and
`Reflect.has`. A name that only the prototype holds, such as
`constructor` or `toString`, now reads as missing: `has("constructor")`
is false, and `object("constructor")` fails as a missing object would.

## Changes

- `src/noldova.ui.components.angular/scripts/angular/json-fields.ts`:
- `count`, `number`, `flag`, `text`, `list`, `object`, `holdsObject` and
`has` read through `fields()`. `has` still reads a null field as
missing.
- `fields()` builds each object's map once and keeps it in a `WeakMap`
keyed by the parsed object, so a read costs no more than before. Without
the cache, each read would copy the object's fields, and the coverage
report, which reads `data.object("statementMap").object(id)` once per
statement, would copy the whole statement map once per statement.
Nothing changes a parsed object after it's read, so a kept map can't go
stale.
- `src/noldova.ui.components.angular/tests/node/json-fields.test.ts`
(new):
  - A prototype name reads as missing; this test fails on main.
- `__proto__` reads as missing when the object has no own field of that
name, where main read `Object.prototype`; this test fails on main.
- An own `__proto__` field, which `JSON.parse` makes, reads as its
value. Main read it the same way, since an own field comes before the
prototype, so this test guards the fix and passes on main.
  - An own field named for a prototype name still reads.
  - Each kind of read still works, and a null field reads as missing.

## Checks

On the Linux, Mac and Windows test machines: `npm ci`, `npm run build`,
`tsc -p scripts/tsconfig.json` and `node --test
tests/node/json-fields.test.ts`. With main's `json-fields.ts`, the new
test fails on Linux at `has("constructor")`. The scripts that use
`JsonFields` (the coverage merge and report, test timing, the node load
entries, the build and the package builder) have no tests of their own:
the type check covers them, and CI's full run exercises the coverage
merge and report on real coverage files.

Agent: DEV7 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
rostislavrotaru added a commit that referenced this pull request Dec 1, 2026
Closes #286

Moves the kit to 0.0.48, with what has merged since 0.0.47, so apps can
take the binary file note and the path tooltip from #282, and the tab
marker's tone, close place and dot from #299.

## What changes

- `version.json` is at 0.0.48.
- `CHANGELOG.md` has the 0.0.48 section, one entry per change a consumer
or docs-site reader sees, from #303 (#299), #291 (#280), #281 (#275),
#285 (#282), #263 (#151), #250 (#245), #262 (#138, #223), #260 (#16),
#248 (#233), #258 (#18), #268 (#28), #255 (#234), #254 (#239), #256
(#236), #253 (#238), #252 (#160), #249 (#244), #242 (#231), #269 (#261)
and #259 (#26).
- Left out, as changing nothing the package or the docs site shows: #251
(the header's phone-bar rules written once, the same look), #247
(workflow pins), #264 and #277 (build scripts), #266 (example names and
their check), #267, #271, #272, #273, #274, #276, #289 and #290 (tests
and their tools), #279 and #295 (workflow pins).

## Checks

No test covers these two files. The product names check reads the new
section in CI; it names no product.

Agent: DEV2 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build.ts: read the manifest in stampManifest without a cast

1 participant