@gate-forge/pack-sqlalchemy 0.8.0 → 0.9.0

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.
package/README.md CHANGED
@@ -30,6 +30,26 @@ with `ast.parse` and reports:
30
30
  | Class with bases but no literal tablename anywhere | class symbol + `no_tablename_source` unresolved entry (the graph resolves through its repo-wide symbol table when a base carries a literal — same-file AND cross-file) |
31
31
  | Plain classes (mixins, no bases, no table facts) | nothing |
32
32
  | Malformed Python file | `PARSE_ERROR` finding with a line number; the file contributes no resources (GF-19) |
33
+ | Class declared in a file under a test directory (`test/`, `tests/`) | nothing — fixtures are not business surface (below) |
34
+
35
+ ### Test directories are not business surface
36
+
37
+ A path is test fixture surface when any of its **directory** segments is
38
+ exactly `test` or `tests` (case-insensitive; `src/test-paths.ts`, mirrored
39
+ in the python detector). Files there are still parsed and still reported in
40
+ `scannedPaths` — the coverage evidence stays honest — but they contribute no
41
+ resource, no unresolved entry, no signal and no duplicate finding to the
42
+ graph.
43
+
44
+ The why is a real adoption blocker: a pytest module that re-declares a
45
+ table on its own `Base` to build rows without touching the application's
46
+ metadata (`__tablename__ = "accounts"` next to the real
47
+ backend/models/account.py) used to enter the graph as a second business
48
+ resource. The real table then collided with its own fixture, stayed
49
+ plane-unresolved and blocked the gate with no honest answer. Excluding test
50
+ directories is not a special case for any one repository — it is the same
51
+ rule `gateforge init` already applied when it refused to infer a business
52
+ plane for a fixture table, now applied to the graph as well.
33
53
 
34
54
  ### Detector vocabulary
35
55
 
@@ -251,12 +271,12 @@ document path can be moved with `planesConfigPath`.
251
271
 
252
272
  ## Per-tenant singletons
253
273
 
254
- A table whose UNIQUE constraint — or whose UNIQUE **index** — includes the
255
- tenant scope column admits at most ONE row per tenant. A `create` of such a
256
- resource is therefore provable only on a brand-new tenant, while the
257
- witness's adapter reads use one process-global login: the create reads as
258
- "the fixed tenant already has that row". The pack reports that as an
259
- ADDITIVE fact and never as a verdict:
274
+ A table whose UNIQUE constraint — or whose UNIQUE **index** — is written
275
+ over the tenancy scope and NOTHING ELSE admits at most ONE row per tenant.
276
+ A `create` of such a resource is therefore provable only on a brand-new
277
+ tenant, while the witness's adapter reads use one process-global login: the
278
+ create reads as "the fixed tenant already has that row". The pack reports
279
+ that as an ADDITIVE fact and never as a verdict:
260
280
 
261
281
  - `attributes.uniqueConstraints` — every declared
262
282
  `UniqueConstraint("a", "b")`, `Index("ix", "a", "b", unique=True)`, and
@@ -265,21 +285,30 @@ ADDITIVE fact and never as a verdict:
265
285
  attribute is **absent** when the table declares no unique constraint, and
266
286
  a computed column expression or a non-literal `unique` flag is never
267
287
  guessed.
268
- - `attributes.singletonPerTenant` — `{constraint, tenantColumn, columns}`,
269
- minted only when BOTH facts are provable: the table's plane evidence is
270
- `tenant` AND one declared unique constraint includes a recognized
271
- tenant-scope column (`TENANT_SCOPE_COLUMNS`: `tenant_id`, `tenant`,
272
- `tenantId`, `tenant_uuid`, `tenant_key`). The first qualifying constraint
273
- in written order is the one reported; every one of them says the same.
288
+ - `attributes.singletonPerTenant` — `{constraint, tenantColumn,
289
+ scopeColumns, columns}`, minted only when BOTH facts are provable: the
290
+ table's plane evidence is `tenant` AND one declared unique constraint
291
+ names tenancy-scope columns ONLY (`TENANT_SCOPE_COLUMNS`: `tenant_id`,
292
+ `tenant`, `tenantId`, `tenant_uuid`, `tenant_key`). `scopeColumns` lists
293
+ the recognized scope columns of that constraint in written order and
294
+ `tenantColumn` is the first of them. The first qualifying constraint in
295
+ written order is the one reported; every one of them says the same.
296
+
297
+ "Scope and nothing else" is the rule. A constraint that merely CONTAINS
298
+ a scope column says something different: `unique (period_id, tenant_id,
299
+ contract_id, recipient_user_id)` admits one row per RECIPIENT per period,
300
+ so many rows per tenant exist and the table is **not** a singleton. Such a
301
+ constraint is left untagged — the `uniqueConstraints` facts stay visible
302
+ so an owner can see exactly why.
274
303
 
275
304
  Both are attributes, not signals: nothing blocks on them. The gate turns
276
305
  the tag into one non-blocking `RESOURCE_SINGLETON_PER_TENANT` advisory per
277
306
  resource that owes a `persistence:create`, naming the constraint, the
278
- tenant column and how to prove it (create the tenant in the test, then
307
+ scope columns and how to prove it (create the tenant in the test, then
279
308
  register that tenant's login with the witness for that session only — see
280
309
  `packages/cli/guides/TEST-ENVIRONMENT.md`). A table on another plane, an
281
- unreviewed table, or a unique constraint that excludes the tenant scope
282
- column is left byte-identical to before.
310
+ unreviewed table, and a unique constraint naming any non-scope column are
311
+ left byte-identical to before.
283
312
 
284
313
  ### Declaring the tenant scope columns
285
314
 
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { createSqlalchemyDetector, DEFAULT_COMMAND, pythonEnvironment, applyPlan
3
3
  export { DEFAULT_PLANES_CONFIG, NO_PLANE_MAPPING, PLANES_CONFIG_PATH, byTableName, planeRuleMatches, readPlanesConfigOrNull, parsePlanesConfigText, resolvePlaneByRules, type PlaneConfigRule, type PlaneContext, type PlaneMatchInput, type PlaneResolution, type PlaneRule, type PlaneRuleHit, type PlanesConfig, type SqlalchemyPlane, } from './planes.js';
4
4
  export { applySingletonTags, singletonTagFor, TENANT_SCOPE_COLUMNS, type SingletonPerTenantFact, } from './singleton.js';
5
5
  export { readTenancyScopeColumnsOrNull, CONFIG_PATH as TENANCY_CONFIG_PATH, } from './tenancy.js';
6
+ export { isTestSourcePath, TEST_PATH_SEGMENTS, } from './test-paths.js';
6
7
  export { EntityAdapterSchema, validateEntityAdapter, type EntityAdapter, type EntityAdapterContext, type NormalizedEntity, type EntityAdapterValidation, } from './adapter-schema.js';
7
8
  /** The default CLI in-process plugin module: `{ discover(paths) }`. */
8
9
  declare const _default: import("./detector.js").SqlalchemyDetector;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,mBAAmB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;;AACvE,wBAA0C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,mBAAmB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;;AACvE,wBAA0C"}
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ export { createSqlalchemyDetector, DEFAULT_COMMAND, pythonEnvironment, applyPlan
27
27
  export { DEFAULT_PLANES_CONFIG, NO_PLANE_MAPPING, PLANES_CONFIG_PATH, byTableName, planeRuleMatches, readPlanesConfigOrNull, parsePlanesConfigText, resolvePlaneByRules, } from './planes.js';
28
28
  export { applySingletonTags, singletonTagFor, TENANT_SCOPE_COLUMNS, } from './singleton.js';
29
29
  export { readTenancyScopeColumnsOrNull, CONFIG_PATH as TENANCY_CONFIG_PATH, } from './tenancy.js';
30
+ export { isTestSourcePath, TEST_PATH_SEGMENTS, } from './test-paths.js';
30
31
  export { EntityAdapterSchema, validateEntityAdapter, } from './adapter-schema.js';
31
32
  /** The default CLI in-process plugin module: `{ discover(paths) }`. */
32
33
  export default createSqlalchemyDetector();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GAGzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GASpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,mBAAmB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAKtB,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;AACvE,eAAe,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GAGzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GASpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,mBAAmB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAKtB,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;AACvE,eAAe,wBAAwB,EAAE,CAAC"}
@@ -1,26 +1,38 @@
1
1
  /**
2
2
  * Per-tenant singleton facts (plan 2026-09-25 Phase 4b item 3a).
3
3
  *
4
- * A table whose UNIQUE constraint — or whose UNIQUE INDEX — includes the
5
- * tenant scope column admits at most ONE row per tenant. A create of such
6
- * a resource is therefore provable only on a brand-new tenant, while the
7
- * witness's adapter reads use one process-global login: the create reads
8
- * as "the fixed tenant already has that row". This module mints the
9
- * additive `singletonPerTenant` attribute that lets the gate TELL the
10
- * owner; it never decides a verdict, never blocks, and never guesses.
11
- * The rule is deliberately narrow and stated in full: BOTH facts must be
12
- * provable statically — the table must carry plane evidence of `tenant`
13
- * (the reviewed decision, resolved by the plane channel) AND one of its
14
- * declared `uniqueConstraints` must include a tenant-scope column. A
15
- * table on another plane, an unreviewed table, or a unique constraint
16
- * that excludes the tenant scope column is left untouched, so the
17
- * output stays byte-identical wherever the tag is not earned.
4
+ * A table whose UNIQUE constraint — or whose UNIQUE INDEX — is declared
5
+ * over EXACTLY the tenancy scope columns admits at most ONE row per
6
+ * tenancy scope. A create of such a resource is therefore provable only
7
+ * on a brand-new tenant, while the witness's adapter reads use one
8
+ * process-global login: the create reads as "the fixed tenant already has
9
+ * that row". This module mints the additive `singletonPerTenant`
10
+ * attribute that lets the gate TELL the owner; it never decides a
11
+ * verdict, never blocks, and never guesses.
12
+ *
13
+ * "Exactly the scope" is the whole rule, and it is deliberately strict:
14
+ * EVERY column of the constraint must be a recognized tenancy-scope
15
+ * column. A constraint that merely CONTAINS a scope column says
16
+ * something else — `unique (period_id, tenant_id, contract_id,
17
+ * recipient_user_id)` says one row per recipient per period, so many
18
+ * rows per tenant exist, and calling that a singleton produced a
19
+ * provably false sentence about a real table (it also mistook a domain
20
+ * `tenant_id` column — the renter — for the tenancy scope). Both facts
21
+ * must therefore be provable statically: the table must carry plane
22
+ * evidence of `tenant` (the reviewed decision, resolved by the plane
23
+ * channel) AND one of its declared `uniqueConstraints` must be written
24
+ * over scope columns only. A table on another plane, an unreviewed
25
+ * table, and a constraint that names any non-scope column are left
26
+ * untouched, so the output stays byte-identical wherever the tag is not
27
+ * earned.
18
28
  *
19
29
  * WHICH columns carry the tenant scope is the owner's call: the default
20
30
  * is {@link TENANT_SCOPE_COLUMNS}, and an application whose scope column
21
31
  * is spelled differently (`contractor_id`, ...) passes its own list, read
22
32
  * from `.gateforge.yml` (`tenancy.scopeColumns`, see `tenancy.ts`). The
23
- * passed list REPLACES the default — it never extends it.
33
+ * passed list REPLACES the default — it never extends it, so a table
34
+ * scoped by a column the owner did not declare stays untagged even when
35
+ * its name resembles the default list.
24
36
  */
25
37
  /** Column names that RESEMBLE the tenant scope of a tenant-plane table. */
26
38
  export declare const TENANT_SCOPE_COLUMNS: readonly string[];
@@ -28,8 +40,17 @@ export declare const TENANT_SCOPE_COLUMNS: readonly string[];
28
40
  export interface SingletonPerTenantFact {
29
41
  /** Declared constraint/index name, or null when it is unnamed. */
30
42
  constraint: string | null;
31
- /** The recognized tenant-scope column inside {@link columns}. */
43
+ /**
44
+ * The first tenancy-scope column of the constraint in written order.
45
+ * Kept for the additive contract; {@link scopeColumns} names them all.
46
+ */
32
47
  tenantColumn: string;
48
+ /**
49
+ * Every recognized tenancy-scope column of the constraint, written
50
+ * order. Under the default list the spellings are ALTERNATIVES, so this
51
+ * is normally one name; a composite declared scope lists them all.
52
+ */
53
+ scopeColumns: readonly string[];
33
54
  /** Every column of the unique constraint/index, written order. */
34
55
  columns: readonly string[];
35
56
  }
@@ -37,10 +58,24 @@ export interface SingletonPerTenantFact {
37
58
  type Attributes = Readonly<Record<string, unknown>>;
38
59
  /**
39
60
  * The unique constraint that makes this table a singleton per tenant,
40
- * or null when no declared constraint includes the tenant scope column.
61
+ * or null when no declared constraint is written over the tenancy scope
62
+ * ALONE.
63
+ *
64
+ * A constraint qualifies only when EVERY column it names is a recognized
65
+ * scope column — it is written over the tenancy scope and nothing else. A
66
+ * constraint that merely CONTAINS a scope column says something else
67
+ * entirely: `unique (period_id, tenant_id, contract_id,
68
+ * recipient_user_id)` allows one row per recipient per period, so many
69
+ * rows per tenant exist and the table is not a singleton. Naming PART of
70
+ * a composite declared scope (`unique (org_id)` under
71
+ * `tenancy.scopeColumns: [org_id, tenant_id]`) still qualifies, and
72
+ * soundly so: at most one row per organization is at most one row per
73
+ * (organization, tenant).
41
74
  *
42
75
  * Args:
43
76
  * attributes: One `sqlalchemy.table` resource's attributes.
77
+ * scopeColumns: The tenancy-scope column names to recognize (default:
78
+ * {@link TENANT_SCOPE_COLUMNS}; an owner-declared list REPLACES it).
44
79
  *
45
80
  * Returns:
46
81
  * SingletonPerTenantFact | null: the deciding constraint's fact, or null.
@@ -1 +1 @@
1
- {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEH,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AASD,sEAAsE;AACtE,KAAK,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAuBpD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,EACtB,YAAY,GAAE,SAAS,MAAM,EAAyB,GACrD,sBAAsB,GAAG,IAAI,CAoB/B;AAED,2DAA2D;A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AC,EAAE,EACvB,YAAY,GAAE,SAAS,MAAM,EAAyB,GACrD,CAAC,EAAE,CAOL"}
package/dist/singleton.js CHANGED
@@ -1,26 +1,38 @@
1
1
  /**
2
2
  * Per-tenant singleton facts (plan 2026-09-25 Phase 4b item 3a).
3
3
  *
4
- * A table whose UNIQUE constraint — or whose UNIQUE INDEX — includes the
5
- * tenant scope column admits at most ONE row per tenant. A create of such
6
- * a resource is therefore provable only on a brand-new tenant, while the
7
- * witness's adapter reads use one process-global login: the create reads
8
- * as "the fixed tenant already has that row". This module mints the
9
- * additive `singletonPerTenant` attribute that lets the gate TELL the
10
- * owner; it never decides a verdict, never blocks, and never guesses.
11
- * The rule is deliberately narrow and stated in full: BOTH facts must be
12
- * provable statically — the table must carry plane evidence of `tenant`
13
- * (the reviewed decision, resolved by the plane channel) AND one of its
14
- * declared `uniqueConstraints` must include a tenant-scope column. A
15
- * table on another plane, an unreviewed table, or a unique constraint
16
- * that excludes the tenant scope column is left untouched, so the
17
- * output stays byte-identical wherever the tag is not earned.
4
+ * A table whose UNIQUE constraint — or whose UNIQUE INDEX — is declared
5
+ * over EXACTLY the tenancy scope columns admits at most ONE row per
6
+ * tenancy scope. A create of such a resource is therefore provable only
7
+ * on a brand-new tenant, while the witness's adapter reads use one
8
+ * process-global login: the create reads as "the fixed tenant already has
9
+ * that row". This module mints the additive `singletonPerTenant`
10
+ * attribute that lets the gate TELL the owner; it never decides a
11
+ * verdict, never blocks, and never guesses.
12
+ *
13
+ * "Exactly the scope" is the whole rule, and it is deliberately strict:
14
+ * EVERY column of the constraint must be a recognized tenancy-scope
15
+ * column. A constraint that merely CONTAINS a scope column says
16
+ * something else — `unique (period_id, tenant_id, contract_id,
17
+ * recipient_user_id)` says one row per recipient per period, so many
18
+ * rows per tenant exist, and calling that a singleton produced a
19
+ * provably false sentence about a real table (it also mistook a domain
20
+ * `tenant_id` column — the renter — for the tenancy scope). Both facts
21
+ * must therefore be provable statically: the table must carry plane
22
+ * evidence of `tenant` (the reviewed decision, resolved by the plane
23
+ * channel) AND one of its declared `uniqueConstraints` must be written
24
+ * over scope columns only. A table on another plane, an unreviewed
25
+ * table, and a constraint that names any non-scope column are left
26
+ * untouched, so the output stays byte-identical wherever the tag is not
27
+ * earned.
18
28
  *
19
29
  * WHICH columns carry the tenant scope is the owner's call: the default
20
30
  * is {@link TENANT_SCOPE_COLUMNS}, and an application whose scope column
21
31
  * is spelled differently (`contractor_id`, ...) passes its own list, read
22
32
  * from `.gateforge.yml` (`tenancy.scopeColumns`, see `tenancy.ts`). The
23
- * passed list REPLACES the default — it never extends it.
33
+ * passed list REPLACES the default — it never extends it, so a table
34
+ * scoped by a column the owner did not declare stays untagged even when
35
+ * its name resembles the default list.
24
36
  */
25
37
  /** Column names that RESEMBLE the tenant scope of a tenant-plane table. */
26
38
  export const TENANT_SCOPE_COLUMNS = Object.freeze([
@@ -56,10 +68,24 @@ function uniqueConstraintOf(value) {
56
68
  }
57
69
  /**
58
70
  * The unique constraint that makes this table a singleton per tenant,
59
- * or null when no declared constraint includes the tenant scope column.
71
+ * or null when no declared constraint is written over the tenancy scope
72
+ * ALONE.
73
+ *
74
+ * A constraint qualifies only when EVERY column it names is a recognized
75
+ * scope column — it is written over the tenancy scope and nothing else. A
76
+ * constraint that merely CONTAINS a scope column says something else
77
+ * entirely: `unique (period_id, tenant_id, contract_id,
78
+ * recipient_user_id)` allows one row per recipient per period, so many
79
+ * rows per tenant exist and the table is not a singleton. Naming PART of
80
+ * a composite declared scope (`unique (org_id)` under
81
+ * `tenancy.scopeColumns: [org_id, tenant_id]`) still qualifies, and
82
+ * soundly so: at most one row per organization is at most one row per
83
+ * (organization, tenant).
60
84
  *
61
85
  * Args:
62
86
  * attributes: One `sqlalchemy.table` resource's attributes.
87
+ * scopeColumns: The tenancy-scope column names to recognize (default:
88
+ * {@link TENANT_SCOPE_COLUMNS}; an owner-declared list REPLACES it).
63
89
  *
64
90
  * Returns:
65
91
  * SingletonPerTenantFact | null: the deciding constraint's fact, or null.
@@ -75,17 +101,23 @@ export function singletonTagFor(attributes, scopeColumns = TENANT_SCOPE_COLUMNS)
75
101
  const constraint = uniqueConstraintOf(raw);
76
102
  if (constraint === null)
77
103
  continue;
104
+ // Every column must be the scope; a single non-scope column means the
105
+ // constraint distinguishes more than the tenancy and admits repeated
106
+ // creates per tenant.
107
+ const scopeInConstraint = constraint.columns.filter((column) => scopeColumns.includes(column));
108
+ if (scopeInConstraint.length !== constraint.columns.length)
109
+ continue;
78
110
  // Written order decides which constraint is reported when several
79
111
  // qualify — deterministic, and every one of them still says the same.
80
- for (const column of constraint.columns) {
81
- if (!scopeColumns.includes(column))
82
- continue;
83
- return {
84
- constraint: constraint.name,
85
- tenantColumn: column,
86
- columns: [...constraint.columns],
87
- };
88
- }
112
+ const first = scopeInConstraint[0];
113
+ if (first === undefined)
114
+ continue;
115
+ return {
116
+ constraint: constraint.name,
117
+ tenantColumn: first,
118
+ scopeColumns: [...scopeInConstraint],
119
+ columns: [...constraint.columns],
120
+ };
89
121
  }
90
122
  return null;
91
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACnE,WAAW;IACX,QAAQ;IACR,UAAU;IACV,aAAa;IACb,YAAY;CACb,CAAC,CAAC;AAsBH;;;GAGG;AACH,SAAS,kBAAkB,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACrF,MAAM,KAAK,GAAG,KAA8D,CAAC;IAC7E,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,C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surface", shared by everything in this pack and by the CLI's
4
+ * plane-proposal steps.
5
+ *
6
+ * WHY it exists (problem 14): `gateforge init` already refused to infer
7
+ * a business plane for a table declared under a test directory, but the
8
+ * RESOURCE GRAPH still ingested those tables. A test module that declares
9
+ * a fixture table with the same name as a real one (a very common pytest
10
+ * pattern) then collided with it, and the real resource became
11
+ * plane-unresolved or unclassified — a blocking entry with no honest
12
+ * answer. A fixture is not business surface: it never carries the plane
13
+ * of the table it copies, so it must not enter the graph at all.
14
+ *
15
+ * The rule is deliberately the narrowest one that covers the convention:
16
+ * a path is test surface when ANY of its DIRECTORY segments is exactly
17
+ * `test` or `tests` (case-insensitive). It is segment-exact, never a
18
+ * string prefix — `contest/` and `tests_old/` are business surface, and
19
+ * so is a file merely NAMED `test_foo.py` next to real models. The
20
+ * detector in `python/gateforge_sqlalchemy_detector/scan.py` applies the
21
+ * identical segment rule; the two must stay in step, which
22
+ * `test/test-directory-models.test.ts` pins by scanning one repo through
23
+ * both.
24
+ */
25
+ /** Directory segments that mark test fixture surface (exact segment match). */
26
+ export declare const TEST_PATH_SEGMENTS: readonly string[];
27
+ /**
28
+ * Whether a repo-relative posix path names test fixture surface.
29
+ *
30
+ * Args:
31
+ * source: Repo-root-relative source path of a resource or route
32
+ * (backslashes accepted and normalized).
33
+ *
34
+ * Returns:
35
+ * boolean: true when any directory segment of the path is `test` or
36
+ * `tests` (case-insensitive); false for everything else, including
37
+ * the repository root and files whose NAME merely starts with `test`.
38
+ */
39
+ export declare function isTestSourcePath(source: string): boolean;
40
+ //# sourceMappingURL=test-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-paths.d.ts","sourceRoot":"","sources":["../src/test-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAAqC,CAAC;AAEtF;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAWxD"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The one generic rule for "this path is test fixture surface, not
3
+ * business surface", shared by everything in this pack and by the CLI's
4
+ * plane-proposal steps.
5
+ *
6
+ * WHY it exists (problem 14): `gateforge init` already refused to infer
7
+ * a business plane for a table declared under a test directory, but the
8
+ * RESOURCE GRAPH still ingested those tables. A test module that declares
9
+ * a fixture table with the same name as a real one (a very common pytest
10
+ * pattern) then collided with it, and the real resource became
11
+ * plane-unresolved or unclassified — a blocking entry with no honest
12
+ * answer. A fixture is not business surface: it never carries the plane
13
+ * of the table it copies, so it must not enter the graph at all.
14
+ *
15
+ * The rule is deliberately the narrowest one that covers the convention:
16
+ * a path is test surface when ANY of its DIRECTORY segments is exactly
17
+ * `test` or `tests` (case-insensitive). It is segment-exact, never a
18
+ * string prefix — `contest/` and `tests_old/` are business surface, and
19
+ * so is a file merely NAMED `test_foo.py` next to real models. The
20
+ * detector in `python/gateforge_sqlalchemy_detector/scan.py` applies the
21
+ * identical segment rule; the two must stay in step, which
22
+ * `test/test-directory-models.test.ts` pins by scanning one repo through
23
+ * both.
24
+ */
25
+ /** Directory segments that mark test fixture surface (exact segment match). */
26
+ export const TEST_PATH_SEGMENTS = Object.freeze(['tests', 'test']);
27
+ /**
28
+ * Whether a repo-relative posix path names test fixture surface.
29
+ *
30
+ * Args:
31
+ * source: Repo-root-relative source path of a resource or route
32
+ * (backslashes accepted and normalized).
33
+ *
34
+ * Returns:
35
+ * boolean: true when any directory segment of the path is `test` or
36
+ * `tests` (case-insensitive); false for everything else, including
37
+ * the repository root and files whose NAME merely starts with `test`.
38
+ */
39
+ export function isTestSourcePath(source) {
40
+ const segments = source
41
+ .replaceAll('\\', '/')
42
+ .split('/')
43
+ // The last segment is the file name itself; only DIRECTORY segments
44
+ // decide, so `models/test_accounts.py` is not test surface while
45
+ // `tests/models.py` is.
46
+ .slice(0, -1);
47
+ return segments.some((segment) => TEST_PATH_SEGMENTS.includes(segment.toLowerCase()));
48
+ }
49
+ //# sourceMappingURL=test-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-paths.js","sourceRoot":"","sources":["../src/test-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,QAAQ,GAAG,MAAM;SACpB,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC;SACrB,KAAK,CAAC,GAAG,CAAC;QACX,oEAAoE;QACpE,iEAAiE;QACjE,wBAAwB;SACvB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAC/B,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CACnD,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gate-forge/pack-sqlalchemy",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "SQLAlchemy CRUD discovery pack: AST-only python detector (GPP/3), in-process TS discover entry, configurable plane mapping, entity-adapter schema.",
6
6
  "type": "module",
@@ -17,7 +17,10 @@
17
17
  "README.md",
18
18
  "dist",
19
19
  "examples",
20
- "python"
20
+ "python",
21
+ "!**/__pycache__",
22
+ "!**/*.pyc",
23
+ "!**/*.pyo"
21
24
  ],
22
25
  "scripts": {
23
26
  "build": "tsc -p tsconfig.build.json",
@@ -25,8 +28,8 @@
25
28
  "test": "vitest run"
26
29
  },
27
30
  "dependencies": {
28
- "@gate-forge/core": "^0.8.0",
29
- "@gate-forge/plugin-protocol": "^0.8.0",
31
+ "@gate-forge/core": "^0.9.0",
32
+ "@gate-forge/plugin-protocol": "^0.9.0",
30
33
  "yaml": "^2.8.1",
31
34
  "zod": "^4.1.5"
32
35
  },
@@ -147,6 +147,34 @@ SOFT_DELETE_CANDIDATE_FIELDS = (
147
147
  "is_deleted",
148
148
  )
149
149
 
150
+ # Directory segments that mark test fixture surface (exact segment match,
151
+ # case-insensitive). Files under such a directory are parsed and reported
152
+ # in ``scannedPaths`` — the coverage evidence stays honest — but they never
153
+ # reach the resource graph: a fixture table is not business surface, and a
154
+ # fixture that re-declares a real table's name used to collide with it and
155
+ # leave the REAL resource plane-unresolved. This mirrors
156
+ # ``packages/pack-sqlalchemy/src/test-paths.ts`` exactly (the TypeScript
157
+ # side applies the same rule to plane proposals and route folders); both
158
+ # must stay in step, which ``test/test-directory-models.test.ts`` pins.
159
+ TEST_PATH_SEGMENTS = ("tests", "test")
160
+
161
+
162
+ def _is_test_path(relpath: str) -> bool:
163
+ """Whether a repo-relative path is test fixture surface.
164
+
165
+ Only DIRECTORY segments decide, so ``models/test_accounts.py`` is not
166
+ test surface while ``tests/models.py`` is, and ``contest/`` is not
167
+ ``test``.
168
+
169
+ Args:
170
+ relpath: Repo-root-relative posix path.
171
+
172
+ Returns:
173
+ bool: True when any directory segment is ``test``/``tests``.
174
+ """
175
+ segments = relpath.replace("\\", "/").split("/")[:-1]
176
+ return any(segment.lower() in TEST_PATH_SEGMENTS for segment in segments)
177
+
150
178
 
151
179
  def expr_label(node: ast.expr) -> str:
152
180
  """Classify a non-literal expression deterministically for UNRESOLVED reasons.
@@ -1814,7 +1842,13 @@ def scan(paths: list[str], root: Path | None = None) -> dict:
1814
1842
  if finding is not None:
1815
1843
  findings.append(finding)
1816
1844
  continue
1845
+ # Coverage evidence records EVERY successfully parsed file, test
1846
+ # fixtures included — a hole in the scan must stay visible. The
1847
+ # index is what feeds the resource graph, and a fixture table is
1848
+ # not business surface (see ``_is_test_path``).
1817
1849
  scanned.append(relpath)
1850
+ if _is_test_path(relpath):
1851
+ continue
1818
1852
  indexes[relpath] = index
1819
1853
  resources: list[dict] = []
1820
1854
  unresolved: list[dict] = []