@srobroek/pi-code-quality 0.16.2 → 0.18.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/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## quality [0.18.0](https://github.com/srobroek/harness-plugins/compare/quality--v0.17.0...quality--v0.18.0) (2026-11-25)
2
+
3
+ ### Features
4
+
5
+ * **quality:** ship quality to OMP ([#200](https://github.com/srobroek/harness-plugins/issues/200)) ([fed762e](https://github.com/srobroek/harness-plugins/commit/fed762ec504dad3a6fed928f78eff7b8b428661a))
6
+
7
+ ## quality [0.17.0](https://github.com/srobroek/harness-plugins/compare/quality--v0.16.2...quality--v0.17.0) (2026-11-25)
8
+
9
+ ### Features
10
+
11
+ * **quality:** add single-source and pattern-dialect rules for contracts ([bb8a0ee](https://github.com/srobroek/harness-plugins/commit/bb8a0ee23d50c34b86d9fce506e10f892933cf1d))
12
+ * **quality:** make TypeSpec the required source of every cross-boundary contract ([5f38c72](https://github.com/srobroek/harness-plugins/commit/5f38c7220fa56716c208266f09d4c185be51a88b))
13
+
14
+ ### Bug Fixes
15
+
16
+ * **quality:** make TypeSpec the source of every serialized or published contract ([8775a34](https://github.com/srobroek/harness-plugins/commit/8775a343fdd44d5b9f57d0e678ccbeea7a1fecee))
17
+ * **toolchain:** recognise TypeSpec's emitted seal, publish OpenAPI 3.2.0, ship the full API skill to OMP and adopt the framework-adapter pattern ([818f193](https://github.com/srobroek/harness-plugins/commit/818f193ecb67974fed549502705b6f5663708797))
18
+
1
19
  ## quality [0.16.2](https://github.com/srobroek/harness-plugins/compare/quality--v0.16.1...quality--v0.16.2) (2026-11-25)
2
20
 
3
21
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srobroek/pi-code-quality",
3
- "version": "0.16.2",
3
+ "version": "0.18.0",
4
4
  "description": "Code design and review guidance, a code-quality policy, testing standards and a test audit, performance profiling, and throwaway logic prototypes.",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -41,7 +41,7 @@ References live in `references/` beside this file; the links below are relative
41
41
  | Logs, traces, metrics, or a new service, worker, CLI or Lambda function → [telemetry.md](references/telemetry.md) | OpenTelemetry by default: setup, export, propagation, sampling, flushing, span/metric/log rules, telemetry tests; SDK packages live in `lang-<language>-libraries` |
42
42
  | Feature flags, rollout decisions, outage defaults or flag storage → [feature-flags.md](references/feature-flags.md) | Typed flag module, edge decisions, safe defaults, storage, testing, telemetry and removal; process lives in `trunk-dev-feature-flags` |
43
43
  | Database state, transitions, migrations, dynamic SQL, or persistence tests → [persistence.md](references/persistence.md) | DB as the record, compare-and-set updates, append-only migrations, bound queries, real-database tests |
44
- | Generated bindings, IPC command names, wire casing, or client/server contract tests → [contracts.md](references/contracts.md) | Committed codegen with drift check, name conformance, one casing, tests against the real surface, stubs behind a contract |
44
+ | A serialized or published contract (HTTP API, config or file format, record, CLI or tool JSON output, event, MCP tool schema); generated bindings, IPC command names, wire casing, or client/server contract tests → [contracts.md](references/contracts.md) | TypeSpec as the one source, committed codegen with drift check, pattern dialect, known generator issues, name conformance, one casing, tests against the real surface, stubs behind a contract |
45
45
  | Plan/approve/apply flows, bulk or destructive file operations, path checks, audit trails → [safe-mutation.md](references/safe-mutation.md) | Apply-time approval tokens, freshness checks, traversal, append-only audit, reversible deletes |
46
46
  | Contracts, internal knowledge, naming, errors, or effects → [supporting-principles.md](references/supporting-principles.md) | Design by Contract, least knowledge, predictability, command-query separation; researched sources and limits |
47
47
  | Go code → [go.md](references/go.md) | Consumer interfaces, structs, composition, package boundaries, errors |
@@ -1,12 +1,65 @@
1
- # Cross-language and wire contracts
1
+ # Serialized and published contracts
2
2
 
3
- Read when two sides of a boundary must agree on names, shapes, or casing: generated bindings or clients (OpenAPI, protobuf, GraphQL, ts-rs, specta), IPC command registries, or JSON payloads shared between a backend and a frontend. API and event compatibility across versions is in [release.md](release.md).
3
+ Read when you add or change a serialized or published contract (an HTTP API, a config, file or record format, CLI or tool JSON output, an event or message payload, an MCP tool schema), or when two sides must agree on names, shapes, or casing: generated bindings or clients (OpenAPI, protobuf, GraphQL, ts-rs, specta), IPC command registries, or JSON payloads shared between a backend and a frontend. API and event compatibility across versions is in [release.md](release.md).
4
4
 
5
5
  ## Generated code is committed and drift-checked
6
6
 
7
- **Do:** generate bindings from the authoritative side, commit the output, and in CI regenerate and run `git diff --exit-code`. That one gate covers the whole generated surface; consumers use it without repeating it.
7
+ **Do:** generate bindings from the authoritative side, commit the output, and in CI regenerate and fail on `git status --porcelain -- <generated dirs>`. It covers the whole generated surface, newly emitted untracked files included (`git diff --exit-code` misses them); consumers use it without repeating it.
8
8
  **Do not:** generate in a postinstall step nobody reviews, or hand-edit generated files. Change the source or the generator.
9
9
 
10
+ ## TypeSpec is the source of every owned contract
11
+
12
+ **Do:** In every project, author each serialized or published contract you own in TypeSpec, even when it stays within one process, language, or repository. Use `@typespec/http` and `@typespec/openapi3` for internal and external HTTP APIs. Use `@typespec/json-schema` for config, file and record formats, CLI and tool JSON output, event and message payloads, and MCP tool input and output schemas. Keep `.proto` for protobuf and gRPC wire contracts and GraphQL SDL for GraphQL APIs. Keep channels and bindings in AsyncAPI and reference the emitted payload schemas until a stable TypeSpec AsyncAPI emitter is available. Vendor third-party schemas as published; do not re-author them. In-memory types that are never serialized or published are out of scope. Generate and commit the applicable artifacts, and generate OpenAPI, JSON Schema, API reference docs and reference documentation from the same source; never edit generated output by hand. Publish a JSON Schema through a generated entry point (each public model emitted separately with `@jsonSchema`, or a root `$ref` wrapper), so validating against the published file rejects an invalid document. Derive any generator-specific copy (a normalized schema) with a pinned script in CI, and never publish it. Complete docs live in the published schema. `toolchain-api` has the routes, versions and CI gates; each `lang-<language>-libraries` has the generator entry.
13
+ **Do not:** hand-write a model class, Zod schema, serde struct or Go struct for such a contract, keep a second schema beside the source, or let a hand-edited emitted file stand in for a source change. A contract change is a TypeSpec change plus a regenerate. A framework (oRPC, FastAPI, Hono, NestJS, Huma) serves and calls the types and validators generated from the emitted output; the schema it exports from code is only a drift check, never a competing source.
14
+
15
+ | Exception | Reason |
16
+ | --- | --- |
17
+ | Protobuf and gRPC wire contracts keep `.proto` | Binary wire format; `buf lint` and `buf breaking` own the checks (`toolchain-api`) |
18
+ | GraphQL APIs keep GraphQL SDL | The schema language is the contract |
19
+ | Channels and bindings stay in AsyncAPI | They reference the emitted payload schemas until a stable TypeSpec AsyncAPI emitter exists |
20
+ | A third-party contract | Vendor their published file as published; generate from it, never re-author it |
21
+ | In-memory types never serialized or published | Out of scope |
22
+
23
+ Any other departure is a recorded decision in the engineering doc with its reason. A construct the spike did not cover (nested unions, recursive models, `int64` or decimal precision, `bytes`) still goes in TypeSpec: add a fixture for it first.
24
+
25
+ ### Why not another source
26
+
27
+ Observed on the spike's 29 fixtures for one contract, 2026-11-25. None beat TypeSpec on any language (Pydantic 28/29, Zod 28/29, Rust 29/29, Go 28/29).
28
+
29
+ | Alternative | Result | Reason |
30
+ | --- | --- | --- |
31
+ | Protobuf with protojson | 23/29 best (protojson plus protovalidate; Rust typify route 23/29) | Cannot carry a `kind`-tagged union or present-but-null; its published JSON Schema fails to compile in Ajv |
32
+ | Smithy | Ties | Only after 8 OpenAPI overrides kept outside the IDL |
33
+ | quicktype | Standalone bindings 13/29 to 19/29; Rust with a separate validator 29/29 but 3/12 on exact round-trip | Enforces types, not constraints |
34
+ | Typical | No JSON route | Binary format only, no constraints |
35
+
36
+ ### Known issues and workarounds
37
+
38
+ | Issue | Workaround |
39
+ | --- | --- |
40
+ | Pydantic reads `\d` as Unicode and accepts `٣` (rust-regex engine) | Write `[0-9]` (pattern rule below); keep the default engine |
41
+ | A lowercase `t` or `z` in a date-time is rejected on the Zod routes (`z.iso.datetime()`) and all Go routes (`time.Parse`) but accepted by Ajv, Python and Rust | No tested generator fixes it. Narrow the contract, or record an exception for that route and fixture with its exact expected result; every other fixture must still match its label |
42
+ | `@hey-api/openapi-ts` drops field descriptions and `datamodel-code-generator` drops model docstrings (3/6 each) | The published schema must carry complete docs and is tested for them; test the docs a binding claims to support in that binding, and record the gap per route |
43
+ | No tested generator handled the emitted bundle unchanged (`unevaluatedProperties`, bundle `$id` refs) | The pinned schema normaliser rewrites them into the generator input; it fails loudly on a construct it cannot rewrite, so run it in the regenerate gate |
44
+ | `cargo-typify` does not enforce ranges, item counts or optional-not-null (25/29) | Validate the raw `serde_json::Value` with the `jsonschema` crate before deserializing (29/29) |
45
+ | The emitted bundle is only `$defs`, so it accepts any document; the spike's 29/29 was measured on the `RunRequest` subschema, not the bundle root | Generate an entry point (a separate file per public model, or a root `$ref` wrapper) and run valid and invalid fixtures against the exact published artifact |
46
+ | `ogen` orders open-object extras randomly | Compare parsed JSON, not bytes, in golden tests (this fixes key order only) |
47
+ | Fractions longer than 6 digits (Pydantic) or 9 digits (typify, ogen) are truncated on round trip | Comparing parsed JSON does not recover lost precision. Test the significant fractional digits, then constrain the precision in the contract or use a lossless representation (an integer count or a string) |
48
+
49
+ ## Pattern dialect
50
+
51
+ Schema `pattern` values run in a different regex engine in each language (ECMAScript, Rust `regex`, RE2, Python `re`, pydantic-core), and they disagree on `\d`, `\w`, `\s`, `$` and Unicode classes. Spike evidence, 9 engines, 2026-11-24.
52
+
53
+ **Do:**
54
+
55
+ - Write ECMA-262 patterns that compile with the `u` flag, anchored as a whole: `^(?:a|b)$`. `^a|b$` anchors one alternative each.
56
+ - Spell classes out: `[0-9]`, `[A-Za-z0-9_]`. Replace `\S` with an explicit class equal to ECMAScript whitespace (space, `\t\n\v\f\r`, U+00A0, U+1680, U+2000 to U+200A, U+2028, U+2029, U+202F, U+205F, U+3000, U+FEFF). `[^ \t\n\r\f\v]` is not equal: it accepts NBSP, which `\S` rejects. Otherwise record the narrowing as a contract change.
57
+ - Use `\p{..}` only for one- or two-letter general categories (`\p{L}`, `\p{Nd}`), and only with a generator that emits the `u` flag. `@hey-api/openapi-ts` does; `json-schema-to-zod`, `z.fromJSONSchema`, `typespec-zod` and the kattebak emitter do not.
58
+ - Keep pydantic-core's default `rust-regex` engine. Python `re` rejects `\p{..}` and its `$` accepts a trailing newline.
59
+ - Lint every emitted schema in CI (no `\d \D \w \W \s \S \b \B`, no lookaround, no backreference, whole-pattern anchoring) and cover each pattern with corpus cases: NBSP, a non-ASCII digit, a trailing newline.
60
+
61
+ **Do not:** rely on RE2, Rust `regex` or pydantic-core for lookaround or backreferences, or claim a pattern migration preserves behavior before the conformance suite has rerun on it. The spike did not rerun on a rule-compliant contract.
62
+
10
63
  ## Names are tested, not trusted
11
64
 
12
65
  **Do:** when one side registers commands or operations by name and the other calls them by string, add a test that fails when the registered set and the called set differ.
@@ -41,6 +41,7 @@ For a branch or work-in-progress review without a caller-supplied PR resource:
41
41
  | Reuse research | Only when the caller supplies it: repository and library candidates examined, choice and sources stated, suitable existing capability reused, concrete gaps justify custom code. Without supplied research, omit this row |
42
42
  | Scope and decisions | Workflow scaled to uncertainty, consequences, and reversibility; coherent increments; consequential rationale and revisit conditions retained |
43
43
  | Verification | Acceptance and failure cases checked; suitable test fidelity; independent expectations; relevant accessibility/performance evidence; no weakened assertions or stale-head claims |
44
+ | Contracts | A serialized or published contract with no authoritative source: TypeSpec for owned contracts, `.proto` or GraphQL SDL for their native protocols, and the published schema for third-party contracts. A hand edit to generated output, or output that cannot be reproduced from the pinned inputs; a second hand-written schema beside the source. A generator-only update (new pinned generator, same source) is not a finding when the output is reproducible. Rules and exceptions: `contracts.md` |
44
45
  | Tests | Test diff matches the code diff: tests for new or changed behavior, a regression test per bug fix, unchanged assertions in a refactor, tests and fixtures deleted with removed behavior, no test that only checks removed code is gone; no tampering (loosened assertions, edited expected values, skips, retries, unreviewed snapshot updates) without a stated requirement; no near-duplicates, private-helper or call-order tests, or mocks of internals. Checklist and severities: the `quality-testing` skill's `review-tests.md` |
45
46
  | Security/dependencies | Changed trust/privilege boundaries, denied cases, sensitive data, dependency fit and maintenance, and relevant artifact identity/provenance |
46
47
  | Release/effects | Active and rollback consumers, stored/queued data, staged compatibility, recovery limits, retries/duplicate effects, observation and temporary-path removal |
@@ -11,6 +11,8 @@ MUST Prioritize SOLID, encapsulation, and protected invariants over YAGNI when t
11
11
 
12
12
  MUST Apply DRY to knowledge that must change together, not to code that merely looks alike. Revisit structure whenever behavior changes.
13
13
 
14
+ MUST In every project, author each serialized or published contract you own in TypeSpec, even when it stays within one process, language, or repository. Use `@typespec/http` and `@typespec/openapi3` for internal and external HTTP APIs. Use `@typespec/json-schema` for config, file and record formats, CLI and tool JSON output, event and message payloads, and MCP tool input and output schemas. Keep `.proto` for protobuf and gRPC wire contracts and GraphQL SDL for GraphQL APIs. Keep channels and bindings in AsyncAPI and reference the emitted payload schemas until a stable TypeSpec AsyncAPI emitter is available. Vendor third-party schemas as published; do not re-author them. In-memory types that are never serialized or published are out of scope. Generate and commit the applicable artifacts, and generate OpenAPI, JSON Schema, API reference docs and reference documentation from the same source; never edit generated output by hand. Never hand-write a model class, Zod schema, serde struct or Go struct for such a contract: change the TypeSpec and regenerate, with the pinned routes in `toolchain-api` and `lang-<language>-libraries`. Report any other departure with its reason. Rules, known issues and the CI gates: `quality-code-design`'s `contracts.md` and `toolchain-api`.
15
+
14
16
  MUST Use OpenFeature through one flag module with one provider over flags.yaml, SSM or AppConfig, chosen by need; ask before writing a missing provider. Decide once at the request or job edge and default to existing behavior. Libraries take caller decisions; plugins keep harness-specific options. See `quality-code-design`'s `feature-flags.md`.
15
17
 
16
18
  MUST Before designing or writing code for a concern, research current best practice (official docs, Context7 when configured for the project, or the web) and compare the plan with the preferred-library standards: `lang-<language>-libraries`, `toolchain-api` for API styles, `aws-guidance` for AWS projects' Lambda and service-client work, else `toolchain-languages`. Prefer the repository's code, the standard library, the framework's features, then a listed library; write your own only for a named gap, and report each departure from a standard. A dependency the request did not name needs the user's approval.