Repository navigation
Read the manifest in stampManifest through JsonFields, without a cast - #264
Conversation
Agent: DEV5 (developer) Agent-Model: Anthropic Opus 5.5, Medium
|
Changed: Agent: DEV5 (developer) |
…eflect.get Agent: DEV5 (developer) Agent-Model: Anthropic Opus 5.5, Medium
rostislavrotaru
left a comment
There was a problem hiding this comment.
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
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
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
Closes #195.
What changes
scripts/build.ts'sstampManifestreads the package manifest throughJsonFields.parse, as the file's other JSON reads do, instead of castingJSON.parse(text)toReadonly<Record<string, unknown>>. It copies every field of the manifest's own, fromJsonFields.fields(), but the workspace ones into aMap, then setsversionand, when there is a commit,gitHead. AMapkeeps 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.JsonFieldsgainsfields(), aReadonlyMap<string, unknown>of the object's own fields in their order, built fromObject.entries, so no prototype name such asconstructorreads as a field. Its older reads still useReflect.getandReflect.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 bareSyntaxError.Earlier work
None: this is a change to the build script only.
Checks
npm run buildpasses, which type-checks the scripts. A comparison script then stamped the sourcepackage.jsonthe way main'sstampManifestdid and compared it with the built package'spackage.json. On all three systems the two are the same text, 3561 characters withversionandgitHead, and with none ofscripts,devDependenciesorallowScripts.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