Repository navigation
Commit f2101d0
fix(scripts): tenant-audit census stores declared type text as written, and resolves names by scope (#19650)
Fixes #19300
Two defects in one file's TypeScript reading, with two independent
fixes. Route ① for
the first, as triage on the predecessor card named it; scope-keyed name
resolution for
the second.
## Defect 1 — the census collapsed declared type text before re-parsing
it
`declaredTypesIn` stored a declared type through
`getText(sf).replace(/\s+/g, ' ')`. The
door rule is later read off that text by re-parsing it as a synthetic
alias
(`type CensusReceiver = THE_STORED_TEXT;`). A type literal may separate
its members by
a NEWLINE alone — legal TypeScript — and the collapse turns that
separator into nothing,
so the synthesis does not parse and the site is refused as
`type-text-not-round-trippable`. The author was told to restyle legal
TypeScript to work
around the tool's own re-serialisation.
The text is now stored exactly as the source spells it. The collapse was
never needed at
the storage boundary: every reader of that text either scans it for
identifiers or
re-parses it, and the one place a single line is genuinely required —
the artefacts —
already collapses at the point of render (`runCensus`, `cell()`).
**The real site set is TWO, not the three the card names.** Measured on
this branch:
| site | in the set? | why |
| :--- | :--- | :--- |
| `note()`'s `type` field | **yes** | feeds `readTypeTextDoor` through
`fromEntry` |
| the `shapes` member type | **yes** | feeds it through
`memberTypeOfShapes` |
| `receiverKey` | no | a receiver's own spelling, for ledger keys and
diagnostics; never re-parsed |
| `note()`'s `init` field | no | a diagnostic, truncated to 120 chars;
scanned by regex, never re-parsed |
| the `as` path's `r.type.getText(sf)` | no | never collapsed in the
first place — it is the lit control that already proved raw text
round-trips |
| the spread / opaque / runtime-name sites | no | diagnostics and object
names, never type texts |
| `:355` in `memberIsEngineDoor` | no | `replace(/\s+/g, '')` — an
**empty** replacement, and its only consumer is `t !== 'string'`. It
normalises for an equality test and is never handed to a parser. |
## Defect 2 — `locals` was keyed by bare identifier, with no scope
A file may contain several `engine`s. Keyed on the identifier alone they
were one entry,
and the first TYPED one decided for all of them. That is **three**
failures, not one, and
which one you get depends on declaration order:
| shape | before | after |
| :--- | :--- | :--- |
| engine-typed `engine` declared first, `Map` second | `Map.delete`
scored an **engine write** and admitted to the certified population |
the Map is subtracted |
| `Map` first, engine-typed second | the **real engine write**
subtracted as `platform-type` — a DEFENDED arm, so it prints nothing and
is counted nowhere | the engine write is placed |
| both engine-typed, one unreadable | both refused (the card's measured
instance) | both placed |
The middle row is the expensive one and the card does not name it: the
census's own header
calls a silent subtraction the direction it cannot survive being wrong
in, and the
bare-name map was producing them.
The conflation also decided two other verdicts the artefacts carry —
**which object** a
site writes (`resolveObjectNameArg`) and **whether it is elevated**
(`elevationOf`). Both
are pinned now.
`declaredTypesIn` resolves a name through its innermost enclosing scope,
with the old
file-wide map kept as an explicit floor tier: consulted only when no
enclosing scope
declares the name, so **no receiver that resolved before stops
resolving**.
## What this moves on the real corpus
The population is unchanged — **227 sites before, 227 after, none added,
none removed**.
Fourteen sites change attribution, and one receiver becomes honestly
unreadable:
- 6 sites stop needing an `UNTYPED_RECEIVERS` row (the census can now
read their declared
type), so three ledger rows are deleted as stale.
- 2 sites in `bootstrap-declared-webhooks.ts` resolve their object name
to `sys_webhook`
for the first time — `undecidable` becomes `enabled`.
- 6 sites in `metadata-store.ts` move from `declared-type` to the
object-name rescue.
Their receiver is a **contextually typed** arrow parameter (`(engine) =>
engine.insert(…)`
against a declared `run: (engine: IDataEngine) => …`), which needs a
type checker this
module does not have. The bare-name map had been answering it from an
unrelated
declaration and happened to be right; the verdict is unchanged either
way.
- 1 receiver — `const db = context.database` in `auth-manager.ts` — was
being answered by a
a `Record` keyed by string declared 2000 lines away and silently
subtracted as
`platform-type`. It is the better-auth adapter bound to the SCIM
transaction, and it
arrives in `UNTYPED_RECEIVERS` saying so.
## ✅ Closed: the artefacts are regenerated in this PR
This PR's originally declared file surface was
`scripts/tenant-audit-census.mjs` plus its
self-test and fixtures, and the defect-2 repair moves the census totals,
which stales the
committed artefacts. The dev **stopped at that fence and declared the
red** rather than
widening silently. The seat then **widened the fence** — the artefacts
ride the source PR
rather than a follow-up card, per the lane rule 「其重生成的 references 产物归源
PR」.
Both steps are done:
1. `node scripts/tenant-audit-census.mjs --write` regenerated
`content/docs/permissions/tenant-audit-census.mdx` and
`docs/audits/2026-08-tenant-audit-write-call-sites.counts.md`.
2. The hand-written prose numbers `--write` does not touch were taken
**from the gate's own
output**, not retyped from any summary: `const` 41→43,
unreadable-and-tenancy-enabled
32→34 (twice), statically decidable 151→153, undecidable 76→74.
`check-tenant-audit-census.mjs` and its `--self-test` are now **green
(27/27, up from 6
failing)**, which also confirms the diagnosis: all six failures were the
drift.
**Defect 1 is artefact-neutral and was measured as such**: with only the
two storage-site
lines changed, the census `--json` is byte-identical to the base tree
(`diff` exit 0 over
the full document). Every count that moves comes from defect 2.
## Verification
All **66** gates `scripts/pm/dispatch-gates.mjs --repo
objectstack-ai/objectstack --commands`
derives for the widened diff were run and reconciled with `--ran` on the
final head:
**66 derived / 66 run / 0 NOT MEASURED / 0 UNRUN, every family carrying
a recorded exit
code, all zero.** The set grew from 29 because the diff now reaches
`content/docs/**`,
`docs/audits/**` and `ts-parse.mjs`.
1 parent 79854f7 commit f2101d0
5 files changed
Lines changed: 357 additions & 122 deletions
File tree
- content/docs/permissions
- docs/audits
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
191 | | - | |
| 190 | + | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
227 | | - | |
228 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
248 | | - | |
| 247 | + | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
199 | | - | |
| 198 | + | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
| |||
0 commit comments