Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(graph): let the #6953 role assertions run and fail on an unfixed tree
time-attack52e979a20230
diff --git a/docs/architecture/key-files/schema-mutation.md b/docs/architecture/key-files/schema-mutation.mdindex 860a983688..90d1d1ae06 100644--- a/docs/architecture/key-files/schema-mutation.md+++ b/docs/architecture/key-files/schema-mutation.md@@ -20,7 +20,7 @@ Key files:- `src/core/schema-pack/query-types.ts` — expands scalar/multiple type filters through the selected engine's active alias graph. Scalar and array filters retain intersection semantics; explicit empty arrays deny before any engine/cache access. Missing packs yield an empty filter that consumers return as no results, never as an unrestricted query; DB lookup failures propagate through keyword, hybrid and image readers. Mixed-pack explicit source scopes refuse rather than arbitrarily choosing a closure. Used by hybrid search and the search/query keyword-only/image bypasses; typed hybrid requests bypass semantic result caching. Tests: `test/schema-engine-isolation.serial.test.ts`, `test/ops-search-types.test.ts`.-- `src/core/schema-pack/entity-types.ts` — #4772: the one answer to "is this stored type an entity" for the counters. `entityTypesFromPack(manifest)` returns the pack's `primitive: entity` type names (plus undeclared aliases of them) and the legacy names (`entity`, `person`, `company`, `organization`) the pack leaves undeclared; a pack that declares a legacy name under another primitive reclassified it and wins. `resolveEntityTypes(engine, scope)` resolves per source (every requested source id, or brain-wide: the brain's pack plus every registered source with a `schema_pack.source.<id>` override) into an `EntityTypeFilter` (default list + per-source lists that differ), and returns `pack_unavailable` with an empty filter when any pack in scope fails to load (the `best-effort.ts` null contract: empty filter, never hardcoded defaults). `entityTypePredicateSql(alias, filter)` renders it as a parameter-bound `sqlFragment`. #6953: `personTypesFromPack` / `resolvePersonTypes` answer "is this type person-like" the same way (per source, same `pack_unavailable` contract): `person` plus its alias closure (`closure.ts`), never primitive siblings; consumer `cycle/edge-contradictions.ts`: its `works_at` members are admitted before grouping and LIMIT only when the subject is person-like by its source's pack (a pack that does not load admits none) and the target is neither person-like nor a `NON_EMPLOYER_TYPES` type (untyped: `NON_EMPLOYER_PREFIXES`; both lists shared with `link-target-roles.ts`'s `targetTakesVerb`); an open proposal made before that rule is not re-checked when applied (`test/edge-employment-roles.test.ts` + Postgres twin). Consumers: `engine-sql/health.ts` through `HealthDeps.entityTypes` (both engines delegate), `commands/doctor/checks/graph-health.ts` (`graph_coverage`, `orphan_ratio`), `onboard/checks.ts` (`entity_link_coverage`, `timeline_coverage`, and `visibleEntityCoverageSql` for `onboard/impact-capture.ts`; a pack that does not load warns `entity_types_unavailable`), `onboard/mcp-onboarding.ts` (the three entity counts are `null` with `entityTypesStatus: pack_unavailable`; the timeline result predicate) and `extract-ner.ts` (the target-type map; `pack_unavailable` when a source's pack does not load). `mentions/policy.ts` keeps its own linkable-type union. Pinned by `test/onboard-entity-types-pack-4772.test.ts`. Lazy-imports the pack loader so the engines can import it statically.+- `src/core/schema-pack/entity-types.ts` — #4772: the one answer to "is this stored type an entity" for the counters. `entityTypesFromPack(manifest)` returns the pack's `primitive: entity` type names (plus undeclared aliases of them) and the legacy names (`entity`, `person`, `company`, `organization`) the pack leaves undeclared; a pack that declares a legacy name under another primitive reclassified it and wins. `resolveEntityTypes(engine, scope)` resolves per source (every requested source id, or brain-wide: the brain's pack plus every registered source with a `schema_pack.source.<id>` override) into an `EntityTypeFilter` (default list + per-source lists that differ), and returns `pack_unavailable` with an empty filter when any pack in scope fails to load (the `best-effort.ts` null contract: empty filter, never hardcoded defaults). `entityTypePredicateSql(alias, filter)` renders it as a parameter-bound `sqlFragment`. #6953: `personTypesFromPack` / `resolvePersonTypes` answer "is this type person-like" the same way (per source, same `pack_unavailable` contract): `person` plus its alias closure (`closure.ts`), never primitive siblings; consumer `cycle/edge-contradictions.ts`: its `works_at` members are admitted before grouping and LIMIT only when the subject is person-like by its source's pack (a pack that does not load admits none) and the target is neither person-like nor a `NON_EMPLOYER_TYPES` type (untyped: `NON_EMPLOYER_PREFIXES`; both lists shared with `link-target-roles.ts`'s `targetTakesVerb`); an open proposal made before that rule is not re-checked when applied (`test/edge-employment-roles.test.ts` + Postgres twin; `personTypesFromPack` in `test/schema-pack-person-types-6953.test.ts`). Consumers: `engine-sql/health.ts` through `HealthDeps.entityTypes` (both engines delegate), `commands/doctor/checks/graph-health.ts` (`graph_coverage`, `orphan_ratio`), `onboard/checks.ts` (`entity_link_coverage`, `timeline_coverage`, and `visibleEntityCoverageSql` for `onboard/impact-capture.ts`; a pack that does not load warns `entity_types_unavailable`), `onboard/mcp-onboarding.ts` (the three entity counts are `null` with `entityTypesStatus: pack_unavailable`; the timeline result predicate) and `extract-ner.ts` (the target-type map; `pack_unavailable` when a source's pack does not load). `mentions/policy.ts` keeps its own linkable-type union. Pinned by `test/onboard-entity-types-pack-4772.test.ts`. Lazy-imports the pack loader so the engines can import it statically.- `src/core/schema-pack/best-effort.ts` — `loadActivePackBestEffort(ctx)` returns `ResolvedPack | null`. Single source of truth for the pack-aware wiring sites. `null` means EMPTY FILTER (NOT hardcoded defaults, which would silently violate the pack). Threads the tier-4 DB-plane `schema_pack` from `ctx.engine`, so every caller resolves the SAME pack `schema active` / `get_active_schema_pack` report. `readDbSchemaPack(engine?)` is the ONE spelling of that tier-4 read (null-safe, propagates DB read failures, trims missing/empty values to undefined) — shared by both loaders here, the CLI inspection verbs (`schema show/graph/lint/explain`, via `readDbSchemaPackConfig` in `src/commands/schema.ts`, which keeps the cfg-null gate so an unconfigured home never cold-creates a PGLite dir) and the MCP `schema_lint`/`schema_graph`/`schema_explain_type` ops. `loadActivePackForLocalEngine(engine)` is the `remote: false` + FILE-ONLY-config variant for local engine-backed surfaces. Pinned by `test/schema-pack-best-effort.test.ts`, `test/operations-schema-pack.test.ts`, `test/schema-cli-db-config.test.ts`.- `src/core/schema-pack/type-usage.ts` — stored-type classifier behind the alias-footgun visibility surfaces: `classifyStoredType(type, pack)` → canonical | alias_of (with the canonical type + `path_prefixes[0]` filing directory) | undeclared, over a STRUCTURAL pack shape so import-file's thin `activePack` and the full manifest both satisfy it. `sanitizeTypeForDisplay` strips control chars + caps length (type strings come from frontmatter and get echoed into terminals); `renderTypeWarningSummary` renders the once-per-type-per-run lines. Consumers: `importFromContent` (advisory `ImportResult.type_warning` at the typeExplicit site — the type is still stored literally, zero filing change), sync/import summary aggregation (+ `SyncResult.type_warnings` so worker-driven syncs surface counts in job results), the `stored_type_is_alias`/`stored_type_undeclared` data-plane lint rules, all gated by config `schema.type_warnings` (default on; lint rules always active). `storedTypeMissesPack(type, pack)` (empty type, or undeclared) is the one predicate every pack-conformance surface uses: `findTypeOrphans` (`schema-pack/review.ts`), `schema_stats` coverage, doctor `schema_pack_consistency`, `gbrain lint`'s `type-undeclared` rule. Pinned by `test/schema-type-usage.test.ts` and `test/schema-pack-type-conformance.test.ts`.- `src/core/schema-pack/lint-rules.ts` — 14 pure rule functions. `withMutation`'s pre-write validation gate composes the 10 file-plane rules; the 4 DB-aware rules (`extractable_empty_corpus`, `mutation_count_anomaly`, `stored_type_is_alias`, `stored_type_undeclared`) need an engine (CLI `--with-db`; the stored-type pair accepts `LintOpts.sourceId` scoping, not yet threaded from the CLI). Single source of truth consumed by CLI lint + MCP `schema_lint` + the pre-write validation gate. File-plane rule `link_regex_catastrophic_backtrack` — advisory ReDoS pre-screen flagging the classic nested-quantifier shapes (`(a+)+`, `(a*)*`, `(a+)*`, `(\w+)+`) in a link_type's `inference.regex` via `NESTED_QUANTIFIER_RE`. WARNING not error: a hard reject would disable the whole pack on upgrade (pages fall back to legacy typing). The runtime input-length cap in `redos-guard.ts` is the actual safety net; this rule tells the pack author to fix the pattern.diff --git a/test/edge-employment-roles.test.ts b/test/edge-employment-roles.test.tsindex b9361c6e4e..fe338079c8 100644--- a/test/edge-employment-roles.test.ts+++ b/test/edge-employment-roles.test.ts@@ -3,13 +3,14 @@* subject (the pack's person type and its alias closure, per source) and an* employer target, before grouping and LIMIT. The judge prompt is unchanged* (D7). PGLite here; Postgres through test/e2e/edge-employment-roles-postgres.test.ts.+ * Imports only APIs that predate the fix, so on an unfixed tree the assertions+ * run and fail (personTypesFromPack is tested in schema-pack-person-types-6953).*/import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';import { mkdtempSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { _resetPackCacheForTests } from '../src/core/schema-pack/registry.ts';-import { personTypesFromPack } from '../src/core/schema-pack/entity-types.ts';import { withEnv } from './helpers/with-env.ts';import { PACKS, writeEntityTypePacks } from './helpers/entity-types-pack-fixture.ts';import type { BrainEngine } from '../src/core/engine.ts';@@ -134,15 +135,6 @@ for (const backend of testBackends()) describe(`employment role admission (${bac});describe('employment inference and evidence policy', () => {- test('person-like types are person plus its alias closure, not primitive siblings', () => {- const pack = { page_types: [- { name: 'person', primitive: 'entity', aliases: [] },- { name: 'researcher', primitive: 'entity', aliases: ['person'] },- { name: 'lab', primitive: 'entity', aliases: [] },- ] } as never;- expect(personTypesFromPack(pack)).toEqual(['person', 'researcher']);- expect(personTypesFromPack({ page_types: [] } as never)).toEqual(['person']);- });test('real link extraction keeps document mentions without inventing employment', async () => {for (const type of ['conversation', 'email', 'source', 'note', 'inbox']) {const { candidates } = await extractPageLinks('people/alice-example',diff --git a/test/schema-pack-person-types-6953.test.ts b/test/schema-pack-person-types-6953.test.tsnew file mode 100644index 0000000000..3e473394fb--- /dev/null+++ b/test/schema-pack-person-types-6953.test.ts@@ -0,0 +1,20 @@+/**+ * #6953: the pack's person-like types are `person` plus every type that+ * aliases it, not every type sharing person's primitive. Kept apart from+ * test/edge-employment-roles.test.ts so that file's behavioral assertions load+ * and run on a tree without this helper.+ */+import { describe, expect, test } from 'bun:test';+import { personTypesFromPack } from '../src/core/schema-pack/entity-types.ts';++describe('personTypesFromPack', () => {+ test('person-like types are person plus its alias closure, not primitive siblings', () => {+ const pack = { page_types: [+ { name: 'person', primitive: 'entity', aliases: [] },+ { name: 'researcher', primitive: 'entity', aliases: ['person'] },+ { name: 'lab', primitive: 'entity', aliases: [] },+ ] } as never;+ expect(personTypesFromPack(pack)).toEqual(['person', 'researcher']);+ expect(personTypesFromPack({ page_types: [] } as never)).toEqual(['person']);+ });+});