devcontour-harness 0.1.0-alpha.44 → 0.1.0-alpha.45

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.
Files changed (49) hide show
  1. package/README.md +11 -2
  2. package/docs/contracts.md +107 -1
  3. package/docs/release-notes/0.1.0-alpha.45.md +77 -0
  4. package/docs/upgrade.md +60 -18
  5. package/lib/contracts/cli.d.ts +67 -0
  6. package/lib/contracts/cli.js +6 -1
  7. package/lib/contracts/events.d.ts +5 -0
  8. package/lib/contracts/events.js +2 -0
  9. package/lib/contracts/execution.d.ts +39 -0
  10. package/lib/contracts/execution.js +15 -2
  11. package/lib/contracts/policy.d.ts +39 -0
  12. package/lib/contracts/policy.js +64 -0
  13. package/lib/contracts/profiles.d.ts +6 -0
  14. package/lib/contracts/published.d.ts +69 -0
  15. package/lib/contracts/result.d.ts +91 -0
  16. package/lib/contracts/result.js +31 -1
  17. package/lib/contracts/review.d.ts +1 -1
  18. package/lib/control/harness.d.ts +24 -2
  19. package/lib/engine/engine.d.ts +18 -3
  20. package/lib/engine/engine.js +74 -8
  21. package/lib/engine/result.js +7 -3
  22. package/lib/engine/runner.d.ts +8 -0
  23. package/lib/engine/runner.js +91 -3
  24. package/lib/environment/git-trust.js +3 -0
  25. package/lib/environment/process.d.ts +2 -0
  26. package/lib/environment/process.js +7 -1
  27. package/lib/explain/state.js +1 -1
  28. package/lib/index.d.ts +1 -0
  29. package/lib/index.js +1 -0
  30. package/lib/integrations/connector/history.js +1 -1
  31. package/lib/integrations/connector/summary.js +2 -1
  32. package/lib/profiles/resolve.d.ts +6 -0
  33. package/lib/projections/attempt.d.ts +4 -2
  34. package/lib/projections/attempt.js +14 -1
  35. package/lib/report/compute.js +4 -3
  36. package/lib/storage/document.d.ts +26 -2
  37. package/lib/verification/acceptance.d.ts +12 -0
  38. package/lib/verification/acceptance.js +62 -7
  39. package/lib/verification/applicability.d.ts +134 -0
  40. package/lib/verification/applicability.js +373 -0
  41. package/lib/verification/gates.d.ts +6 -0
  42. package/lib/verification/proof.d.ts +18 -4
  43. package/lib/verification/proof.js +52 -9
  44. package/package.json +1 -1
  45. package/schemas/execution-document.schema.json +73 -1
  46. package/schemas/execution-policy.schema.json +38 -0
  47. package/schemas/result-envelope.schema.json +138 -2
  48. package/schemas/run-event.schema.json +4 -0
  49. package/schemas/run-result.schema.json +138 -2
@@ -711,6 +711,7 @@ export declare const attemptViewSchema: z.ZodObject<{
711
711
  passed: z.ZodNumber;
712
712
  failed: z.ZodNumber;
713
713
  remaining: z.ZodNumber;
714
+ notApplicable: z.ZodOptional<z.ZodNumber>;
714
715
  }, z.core.$strict>;
715
716
  liveness: z.ZodOptional<z.ZodObject<{
716
717
  state: z.ZodEnum<{
@@ -1210,6 +1211,7 @@ export declare const statusDataSchema: z.ZodObject<{
1210
1211
  passed: z.ZodNumber;
1211
1212
  failed: z.ZodNumber;
1212
1213
  remaining: z.ZodNumber;
1214
+ notApplicable: z.ZodOptional<z.ZodNumber>;
1213
1215
  }, z.core.$strict>;
1214
1216
  liveness: z.ZodOptional<z.ZodObject<{
1215
1217
  state: z.ZodEnum<{
@@ -1314,6 +1316,7 @@ export declare const eventsDataSchema: z.ZodObject<{
1314
1316
  passed: z.ZodBoolean;
1315
1317
  evidenceId: z.ZodString;
1316
1318
  consumer: z.ZodOptional<z.ZodString>;
1319
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
1317
1320
  recheck: z.ZodOptional<z.ZodObject<{
1318
1321
  of: z.ZodString;
1319
1322
  outcome: z.ZodEnum<{
@@ -1812,6 +1815,7 @@ export declare const eventsDataSchema: z.ZodObject<{
1812
1815
  passed: z.ZodBoolean;
1813
1816
  evidenceId: z.ZodString;
1814
1817
  consumer: z.ZodOptional<z.ZodString>;
1818
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
1815
1819
  recheck: z.ZodOptional<z.ZodObject<{
1816
1820
  of: z.ZodString;
1817
1821
  outcome: z.ZodEnum<{
@@ -2549,6 +2553,9 @@ export declare const profileDataSchema: z.ZodObject<{
2549
2553
  path: z.ZodString;
2550
2554
  }, z.core.$strict>;
2551
2555
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
2556
+ when: z.ZodOptional<z.ZodObject<{
2557
+ paths: z.ZodArray<z.ZodString>;
2558
+ }, z.core.$strict>>;
2552
2559
  id: z.ZodString;
2553
2560
  command: z.ZodArray<z.ZodString>;
2554
2561
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -2565,6 +2572,9 @@ export declare const profileDataSchema: z.ZodObject<{
2565
2572
  path: z.ZodString;
2566
2573
  }, z.core.$strict>>;
2567
2574
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
2575
+ when: z.ZodOptional<z.ZodObject<{
2576
+ paths: z.ZodArray<z.ZodString>;
2577
+ }, z.core.$strict>>;
2568
2578
  id: z.ZodString;
2569
2579
  command: z.ZodArray<z.ZodString>;
2570
2580
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -4025,6 +4035,7 @@ export declare const cliDataSchemas: {
4025
4035
  passed: z.ZodNumber;
4026
4036
  failed: z.ZodNumber;
4027
4037
  remaining: z.ZodNumber;
4038
+ notApplicable: z.ZodOptional<z.ZodNumber>;
4028
4039
  }, z.core.$strict>;
4029
4040
  liveness: z.ZodOptional<z.ZodObject<{
4030
4041
  state: z.ZodEnum<{
@@ -4129,6 +4140,7 @@ export declare const cliDataSchemas: {
4129
4140
  passed: z.ZodBoolean;
4130
4141
  evidenceId: z.ZodString;
4131
4142
  consumer: z.ZodOptional<z.ZodString>;
4143
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
4132
4144
  recheck: z.ZodOptional<z.ZodObject<{
4133
4145
  of: z.ZodString;
4134
4146
  outcome: z.ZodEnum<{
@@ -4627,6 +4639,7 @@ export declare const cliDataSchemas: {
4627
4639
  passed: z.ZodBoolean;
4628
4640
  evidenceId: z.ZodString;
4629
4641
  consumer: z.ZodOptional<z.ZodString>;
4642
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
4630
4643
  recheck: z.ZodOptional<z.ZodObject<{
4631
4644
  of: z.ZodString;
4632
4645
  outcome: z.ZodEnum<{
@@ -5302,6 +5315,7 @@ export declare const cliDataSchemas: {
5302
5315
  test: "test";
5303
5316
  property: "property";
5304
5317
  consumer: "consumer";
5318
+ "not-applicable": "not-applicable";
5305
5319
  }>;
5306
5320
  phase: z.ZodEnum<{
5307
5321
  candidate: "candidate";
@@ -5338,6 +5352,17 @@ export declare const cliDataSchemas: {
5338
5352
  }, z.core.$strict>>;
5339
5353
  }, z.core.$strict>>;
5340
5354
  }, z.core.$strict>>;
5355
+ notApplicable: z.ZodOptional<z.ZodObject<{
5356
+ gateDigest: z.ZodString;
5357
+ patterns: z.ZodArray<z.ZodString>;
5358
+ ranges: z.ZodArray<z.ZodObject<{
5359
+ from: z.ZodString;
5360
+ to: z.ZodString;
5361
+ }, z.core.$strict>>;
5362
+ count: z.ZodNumber;
5363
+ files: z.ZodArray<z.ZodString>;
5364
+ pathsDigest: z.ZodString;
5365
+ }, z.core.$strict>>;
5341
5366
  reviewer: z.ZodOptional<z.ZodObject<{
5342
5367
  runtime: z.ZodEnum<{
5343
5368
  codex: "codex";
@@ -5526,6 +5551,7 @@ export declare const cliDataSchemas: {
5526
5551
  test: "test";
5527
5552
  property: "property";
5528
5553
  consumer: "consumer";
5554
+ "not-applicable": "not-applicable";
5529
5555
  }>;
5530
5556
  phase: z.ZodEnum<{
5531
5557
  candidate: "candidate";
@@ -5562,6 +5588,17 @@ export declare const cliDataSchemas: {
5562
5588
  }, z.core.$strict>>;
5563
5589
  }, z.core.$strict>>;
5564
5590
  }, z.core.$strict>>;
5591
+ notApplicable: z.ZodOptional<z.ZodObject<{
5592
+ gateDigest: z.ZodString;
5593
+ patterns: z.ZodArray<z.ZodString>;
5594
+ ranges: z.ZodArray<z.ZodObject<{
5595
+ from: z.ZodString;
5596
+ to: z.ZodString;
5597
+ }, z.core.$strict>>;
5598
+ count: z.ZodNumber;
5599
+ files: z.ZodArray<z.ZodString>;
5600
+ pathsDigest: z.ZodString;
5601
+ }, z.core.$strict>>;
5565
5602
  reviewer: z.ZodOptional<z.ZodObject<{
5566
5603
  runtime: z.ZodEnum<{
5567
5604
  codex: "codex";
@@ -5726,6 +5763,7 @@ export declare const cliDataSchemas: {
5726
5763
  test: "test";
5727
5764
  property: "property";
5728
5765
  consumer: "consumer";
5766
+ "not-applicable": "not-applicable";
5729
5767
  }>;
5730
5768
  phase: z.ZodEnum<{
5731
5769
  candidate: "candidate";
@@ -5762,6 +5800,17 @@ export declare const cliDataSchemas: {
5762
5800
  }, z.core.$strict>>;
5763
5801
  }, z.core.$strict>>;
5764
5802
  }, z.core.$strict>>;
5803
+ notApplicable: z.ZodOptional<z.ZodObject<{
5804
+ gateDigest: z.ZodString;
5805
+ patterns: z.ZodArray<z.ZodString>;
5806
+ ranges: z.ZodArray<z.ZodObject<{
5807
+ from: z.ZodString;
5808
+ to: z.ZodString;
5809
+ }, z.core.$strict>>;
5810
+ count: z.ZodNumber;
5811
+ files: z.ZodArray<z.ZodString>;
5812
+ pathsDigest: z.ZodString;
5813
+ }, z.core.$strict>>;
5765
5814
  reviewer: z.ZodOptional<z.ZodObject<{
5766
5815
  runtime: z.ZodEnum<{
5767
5816
  codex: "codex";
@@ -5950,6 +5999,7 @@ export declare const cliDataSchemas: {
5950
5999
  test: "test";
5951
6000
  property: "property";
5952
6001
  consumer: "consumer";
6002
+ "not-applicable": "not-applicable";
5953
6003
  }>;
5954
6004
  phase: z.ZodEnum<{
5955
6005
  candidate: "candidate";
@@ -5986,6 +6036,17 @@ export declare const cliDataSchemas: {
5986
6036
  }, z.core.$strict>>;
5987
6037
  }, z.core.$strict>>;
5988
6038
  }, z.core.$strict>>;
6039
+ notApplicable: z.ZodOptional<z.ZodObject<{
6040
+ gateDigest: z.ZodString;
6041
+ patterns: z.ZodArray<z.ZodString>;
6042
+ ranges: z.ZodArray<z.ZodObject<{
6043
+ from: z.ZodString;
6044
+ to: z.ZodString;
6045
+ }, z.core.$strict>>;
6046
+ count: z.ZodNumber;
6047
+ files: z.ZodArray<z.ZodString>;
6048
+ pathsDigest: z.ZodString;
6049
+ }, z.core.$strict>>;
5989
6050
  reviewer: z.ZodOptional<z.ZodObject<{
5990
6051
  runtime: z.ZodEnum<{
5991
6052
  codex: "codex";
@@ -6142,6 +6203,9 @@ export declare const cliDataSchemas: {
6142
6203
  path: z.ZodString;
6143
6204
  }, z.core.$strict>;
6144
6205
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
6206
+ when: z.ZodOptional<z.ZodObject<{
6207
+ paths: z.ZodArray<z.ZodString>;
6208
+ }, z.core.$strict>>;
6145
6209
  id: z.ZodString;
6146
6210
  command: z.ZodArray<z.ZodString>;
6147
6211
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -6158,6 +6222,9 @@ export declare const cliDataSchemas: {
6158
6222
  path: z.ZodString;
6159
6223
  }, z.core.$strict>>;
6160
6224
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
6225
+ when: z.ZodOptional<z.ZodObject<{
6226
+ paths: z.ZodArray<z.ZodString>;
6227
+ }, z.core.$strict>>;
6161
6228
  id: z.ZodString;
6162
6229
  command: z.ZodArray<z.ZodString>;
6163
6230
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -795,13 +795,18 @@ export const attemptViewSchema = z.strictObject({
795
795
  sinceHeartbeatMs: z.number().int().min(0).optional(),
796
796
  stale: z.boolean(),
797
797
  }),
798
- /** Обязательные gates текущей фазы на её текущем SHA: `passed + failed + remaining = required`. */
798
+ /**
799
+ * Обязательные gates текущей фазы на её текущем SHA:
800
+ * `passed + failed + remaining (+ notApplicable) = required`.
801
+ */
799
802
  gates: z.strictObject({
800
803
  phase: z.enum(['candidate', 'integration']),
801
804
  required: z.number().int().min(0),
802
805
  passed: z.number().int().min(0),
803
806
  failed: z.number().int().min(0),
804
807
  remaining: z.number().int().min(0),
808
+ /** Не исполнены по `when.paths` (нет поля — таких нет). */
809
+ notApplicable: z.number().int().positive().optional(),
805
810
  }),
806
811
  /** Живость по обходу controller; `idleMs` — только у `quiet` и `stalled`. */
807
812
  liveness: z
@@ -114,6 +114,7 @@ export declare const eventPayloads: {
114
114
  passed: z.ZodBoolean;
115
115
  evidenceId: z.ZodString;
116
116
  consumer: z.ZodOptional<z.ZodString>;
117
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
117
118
  recheck: z.ZodOptional<z.ZodObject<{
118
119
  of: z.ZodString;
119
120
  outcome: z.ZodEnum<{
@@ -737,6 +738,7 @@ export declare const runEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
737
738
  passed: z.ZodBoolean;
738
739
  evidenceId: z.ZodString;
739
740
  consumer: z.ZodOptional<z.ZodString>;
741
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
740
742
  recheck: z.ZodOptional<z.ZodObject<{
741
743
  of: z.ZodString;
742
744
  outcome: z.ZodEnum<{
@@ -1235,6 +1237,7 @@ export declare const runEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1235
1237
  passed: z.ZodBoolean;
1236
1238
  evidenceId: z.ZodString;
1237
1239
  consumer: z.ZodOptional<z.ZodString>;
1240
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
1238
1241
  recheck: z.ZodOptional<z.ZodObject<{
1239
1242
  of: z.ZodString;
1240
1243
  outcome: z.ZodEnum<{
@@ -1763,6 +1766,7 @@ export declare const readRunEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1763
1766
  passed: z.ZodBoolean;
1764
1767
  evidenceId: z.ZodString;
1765
1768
  consumer: z.ZodOptional<z.ZodString>;
1769
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
1766
1770
  recheck: z.ZodOptional<z.ZodObject<{
1767
1771
  of: z.ZodString;
1768
1772
  outcome: z.ZodEnum<{
@@ -2261,6 +2265,7 @@ export declare const readRunEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
2261
2265
  passed: z.ZodBoolean;
2262
2266
  evidenceId: z.ZodString;
2263
2267
  consumer: z.ZodOptional<z.ZodString>;
2268
+ notApplicable: z.ZodOptional<z.ZodLiteral<true>>;
2264
2269
  recheck: z.ZodOptional<z.ZodObject<{
2265
2270
  of: z.ZodString;
2266
2271
  outcome: z.ZodEnum<{
@@ -115,6 +115,8 @@ export const eventPayloads = {
115
115
  passed: z.boolean(),
116
116
  evidenceId: z.string().min(1).max(200),
117
117
  consumer: idSchema.optional(),
118
+ /** Gate с `when.paths` не исполнялся: diff фазы его не задел (не PASS и не провал). */
119
+ notApplicable: z.literal(true).optional(),
118
120
  /** Повтор провала интеграции: повторённая запись и исход. */
119
121
  recheck: z
120
122
  .strictObject({
@@ -332,6 +332,7 @@ export declare const evidenceRecordSchema: z.ZodObject<{
332
332
  kind: z.ZodEnum<{
333
333
  review: "review";
334
334
  test: "test";
335
+ "not-applicable": "not-applicable";
335
336
  }>;
336
337
  phase: z.ZodEnum<{
337
338
  candidate: "candidate";
@@ -572,6 +573,18 @@ export declare const evidenceRecordSchema: z.ZodObject<{
572
573
  skippedMore: z.ZodOptional<z.ZodNumber>;
573
574
  }, z.core.$strict>>;
574
575
  checks: z.ZodOptional<z.ZodString>;
576
+ gateBasis: z.ZodOptional<z.ZodString>;
577
+ notApplicable: z.ZodOptional<z.ZodObject<{
578
+ gateDigest: z.ZodString;
579
+ patterns: z.ZodArray<z.ZodString>;
580
+ ranges: z.ZodArray<z.ZodObject<{
581
+ from: z.ZodString;
582
+ to: z.ZodString;
583
+ }, z.core.$strict>>;
584
+ count: z.ZodNumber;
585
+ files: z.ZodArray<z.ZodString>;
586
+ pathsDigest: z.ZodString;
587
+ }, z.core.$strict>>;
575
588
  alreadySatisfied: z.ZodOptional<z.ZodObject<{
576
589
  gates: z.ZodArray<z.ZodString>;
577
590
  evidence: z.ZodString;
@@ -992,6 +1005,7 @@ export declare const attemptStateSchema: z.ZodObject<{
992
1005
  kind: z.ZodEnum<{
993
1006
  review: "review";
994
1007
  test: "test";
1008
+ "not-applicable": "not-applicable";
995
1009
  }>;
996
1010
  phase: z.ZodEnum<{
997
1011
  candidate: "candidate";
@@ -1232,6 +1246,18 @@ export declare const attemptStateSchema: z.ZodObject<{
1232
1246
  skippedMore: z.ZodOptional<z.ZodNumber>;
1233
1247
  }, z.core.$strict>>;
1234
1248
  checks: z.ZodOptional<z.ZodString>;
1249
+ gateBasis: z.ZodOptional<z.ZodString>;
1250
+ notApplicable: z.ZodOptional<z.ZodObject<{
1251
+ gateDigest: z.ZodString;
1252
+ patterns: z.ZodArray<z.ZodString>;
1253
+ ranges: z.ZodArray<z.ZodObject<{
1254
+ from: z.ZodString;
1255
+ to: z.ZodString;
1256
+ }, z.core.$strict>>;
1257
+ count: z.ZodNumber;
1258
+ files: z.ZodArray<z.ZodString>;
1259
+ pathsDigest: z.ZodString;
1260
+ }, z.core.$strict>>;
1235
1261
  alreadySatisfied: z.ZodOptional<z.ZodObject<{
1236
1262
  gates: z.ZodArray<z.ZodString>;
1237
1263
  evidence: z.ZodString;
@@ -3665,6 +3691,7 @@ export declare const executionDocumentSchema: z.ZodObject<{
3665
3691
  kind: z.ZodEnum<{
3666
3692
  review: "review";
3667
3693
  test: "test";
3694
+ "not-applicable": "not-applicable";
3668
3695
  }>;
3669
3696
  phase: z.ZodEnum<{
3670
3697
  candidate: "candidate";
@@ -3905,6 +3932,18 @@ export declare const executionDocumentSchema: z.ZodObject<{
3905
3932
  skippedMore: z.ZodOptional<z.ZodNumber>;
3906
3933
  }, z.core.$strict>>;
3907
3934
  checks: z.ZodOptional<z.ZodString>;
3935
+ gateBasis: z.ZodOptional<z.ZodString>;
3936
+ notApplicable: z.ZodOptional<z.ZodObject<{
3937
+ gateDigest: z.ZodString;
3938
+ patterns: z.ZodArray<z.ZodString>;
3939
+ ranges: z.ZodArray<z.ZodObject<{
3940
+ from: z.ZodString;
3941
+ to: z.ZodString;
3942
+ }, z.core.$strict>>;
3943
+ count: z.ZodNumber;
3944
+ files: z.ZodArray<z.ZodString>;
3945
+ pathsDigest: z.ZodString;
3946
+ }, z.core.$strict>>;
3908
3947
  alreadySatisfied: z.ZodOptional<z.ZodObject<{
3909
3948
  gates: z.ZodArray<z.ZodString>;
3910
3949
  evidence: z.ZodString;
@@ -3,7 +3,7 @@ import { STATE_VERSION } from "./version.js";
3
3
  import { digestSchema, gitShaSchema, idSchema, isoTimeSchema, relativePathSchema, runtimeNameSchema, trimmedText, gateScopeSchema, } from "./primitives.js";
4
4
  import { workGraphSchema, workOrderSchema } from "./work.js";
5
5
  import { contextPinSchema, contextSnapshotSchema } from "./context.js";
6
- import { deliveryStateSchema, gateArtifactFilesSchema, jointActiveSchema, jointFailedSchema, jointPassedSchema, } from "./result.js";
6
+ import { deliveryStateSchema, gateApplicabilitySchema, gateArtifactFilesSchema, jointActiveSchema, jointFailedSchema, jointPassedSchema, } from "./result.js";
7
7
  import { findingStatuses, reviewRecordSchema, reviewRoundSchema } from "./review.js";
8
8
  import { contractDocumentSchema, spikeSchema } from "./checks.js";
9
9
  import { INPUT_LIMITS, inputPolicySchema, inputRequestSchema, recordedAssumptionSchema, } from "./input.js";
@@ -288,7 +288,11 @@ export const evidenceFindingSchema = z.strictObject({
288
288
  export const evidenceRecordSchema = z.strictObject({
289
289
  id: z.string().min(1).max(200),
290
290
  runId: z.string().min(1).max(200),
291
- kind: z.enum(['test', 'review']),
291
+ /**
292
+ * `not-applicable` — gate с `when.paths` не исполнялся: diff фазы его не
293
+ * задел (`notApplicable`). Такая запись всегда `passed: false` и не PASS.
294
+ */
295
+ kind: z.enum(['test', 'review', 'not-applicable']),
292
296
  phase: z.enum(['candidate', 'integration']),
293
297
  sha: gitShaSchema,
294
298
  /** ID gate; для ревью — `independent-review`. */
@@ -331,6 +335,15 @@ export const evidenceRecordSchema = z.strictObject({
331
335
  artifactFiles: gateArtifactFilesSchema.optional(),
332
336
  /** Действующая версия проверок, под которой получено evidence. */
333
337
  checks: digestSchema.optional(),
338
+ /**
339
+ * Основание исполнения gate с `when` (`gateBasis`: определение, ресурсы,
340
+ * окружение, подготовка, изоляция, версия harness) у собственной записи
341
+ * `test` попытки: по нему ищется последний зелёный SHA gate. Нет у gates
342
+ * без `when` и у прежних записей.
343
+ */
344
+ gateBasis: digestSchema.optional(),
345
+ /** Только у записи `not-applicable`: правило и diff, по которым gate не исполнялся. */
346
+ notApplicable: gateApplicabilitySchema.optional(),
334
347
  /**
335
348
  * Ревью попытки без изменений подтвердило, что приёмка уже выполнена на
336
349
  * базе: gates, на которые сослался reviewer, и его основание.
@@ -29,6 +29,22 @@ export declare const lifecycleSchema: z.ZodObject<{
29
29
  timeoutMs: z.ZodDefault<z.ZodNumber>;
30
30
  }, z.core.$strict>>;
31
31
  }, z.core.$strict>;
32
+ /**
33
+ * Почему шаблон пути `when.paths` недопустим, или undefined. Шаблон —
34
+ * относительный POSIX-glob от корня репозитория: `**`, `*`, `?` и `{a,b}` без
35
+ * вложенности; без `..`, `.`, пустых сегментов, ведущего `/`, обратной
36
+ * косой черты, отрицания и классов символов.
37
+ */
38
+ export declare function gatePathPatternProblem(pattern: string): string | undefined;
39
+ /**
40
+ * Условие применимости gate задачи: gate исполняется, только когда настоящий
41
+ * diff фазы (из Git, не заявление исполнителя) задевает один из путей или
42
+ * неявный вход gate; иначе пишется запись `not-applicable`, которая не PASS.
43
+ * Необязательное поле без умолчания: политика без него сохраняет digest.
44
+ */
45
+ export declare const gateWhenSchema: z.ZodObject<{
46
+ paths: z.ZodArray<z.ZodString>;
47
+ }, z.core.$strict>;
32
48
  export declare const gateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
33
49
  kind: z.ZodLiteral<"test">;
34
50
  report: z.ZodObject<{
@@ -36,6 +52,9 @@ export declare const gateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
36
52
  path: z.ZodString;
37
53
  }, z.core.$strict>;
38
54
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
55
+ when: z.ZodOptional<z.ZodObject<{
56
+ paths: z.ZodArray<z.ZodString>;
57
+ }, z.core.$strict>>;
39
58
  id: z.ZodString;
40
59
  command: z.ZodArray<z.ZodString>;
41
60
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -52,6 +71,9 @@ export declare const gateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
52
71
  path: z.ZodString;
53
72
  }, z.core.$strict>>;
54
73
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
74
+ when: z.ZodOptional<z.ZodObject<{
75
+ paths: z.ZodArray<z.ZodString>;
76
+ }, z.core.$strict>>;
55
77
  id: z.ZodString;
56
78
  command: z.ZodArray<z.ZodString>;
57
79
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -63,6 +85,11 @@ export declare const gateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
63
85
  resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
86
  }, z.core.$strict>], "kind">;
65
87
  export type GatePolicy = z.infer<typeof gateSchema>;
88
+ /**
89
+ * Digest определения gate задачи (с `when`): под ним записывается решение о
90
+ * применимости. Смена команды, путей или любого поля — другой digest.
91
+ */
92
+ export declare const gateDigest: (gate: GatePolicy) => string;
66
93
  /** Группы gates: не больше 100 групп по 100 ссылок, члены — gates или группы (`@имя`). */
67
94
  export declare const gateGroupsSchema: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
68
95
  /** Gate совместной проверки: выполняется в дереве `repositoryId`, сохраняет `artifacts`. */
@@ -337,6 +364,9 @@ export declare const repositoryPolicySchema: z.ZodObject<{
337
364
  path: z.ZodString;
338
365
  }, z.core.$strict>;
339
366
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
367
+ when: z.ZodOptional<z.ZodObject<{
368
+ paths: z.ZodArray<z.ZodString>;
369
+ }, z.core.$strict>>;
340
370
  id: z.ZodString;
341
371
  command: z.ZodArray<z.ZodString>;
342
372
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -353,6 +383,9 @@ export declare const repositoryPolicySchema: z.ZodObject<{
353
383
  path: z.ZodString;
354
384
  }, z.core.$strict>>;
355
385
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
386
+ when: z.ZodOptional<z.ZodObject<{
387
+ paths: z.ZodArray<z.ZodString>;
388
+ }, z.core.$strict>>;
356
389
  id: z.ZodString;
357
390
  command: z.ZodArray<z.ZodString>;
358
391
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -600,6 +633,9 @@ export declare const executionPolicySchema: z.ZodObject<{
600
633
  path: z.ZodString;
601
634
  }, z.core.$strict>;
602
635
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
636
+ when: z.ZodOptional<z.ZodObject<{
637
+ paths: z.ZodArray<z.ZodString>;
638
+ }, z.core.$strict>>;
603
639
  id: z.ZodString;
604
640
  command: z.ZodArray<z.ZodString>;
605
641
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -616,6 +652,9 @@ export declare const executionPolicySchema: z.ZodObject<{
616
652
  path: z.ZodString;
617
653
  }, z.core.$strict>>;
618
654
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
655
+ when: z.ZodOptional<z.ZodObject<{
656
+ paths: z.ZodArray<z.ZodString>;
657
+ }, z.core.$strict>>;
619
658
  id: z.ZodString;
620
659
  command: z.ZodArray<z.ZodString>;
621
660
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -48,20 +48,76 @@ const junitReport = z.strictObject({ type: z.literal('junit'), path: relativePat
48
48
  * Необязательное поле без умолчания: политика без него сохраняет digest.
49
49
  */
50
50
  const gateArtifacts = z.array(relativePathSchema).min(1).max(gateArtifactLimits.paths).optional();
51
+ /**
52
+ * Почему шаблон пути `when.paths` недопустим, или undefined. Шаблон —
53
+ * относительный POSIX-glob от корня репозитория: `**`, `*`, `?` и `{a,b}` без
54
+ * вложенности; без `..`, `.`, пустых сегментов, ведущего `/`, обратной
55
+ * косой черты, отрицания и классов символов.
56
+ */
57
+ export function gatePathPatternProblem(pattern) {
58
+ if (pattern.startsWith('/'))
59
+ return 'шаблон пути не может быть абсолютным';
60
+ if (/[\\\0\[\]]/.test(pattern))
61
+ return 'обратная косая черта, NUL и [] в шаблоне не допускаются';
62
+ if (pattern.startsWith('!'))
63
+ return 'отрицание в шаблоне не поддерживается';
64
+ const body = pattern.endsWith('/') ? pattern.slice(0, -1) : pattern;
65
+ if (body.split('/').some((s) => s === '' || s === '.' || s === '..'))
66
+ return 'шаблон пути без пустых сегментов, . и ..';
67
+ // И внутри вариантов `{}`: `{..,x}` — тот же выход за корень.
68
+ if (body.split(/[/{},]/).some((s) => s === '.' || s === '..'))
69
+ return 'шаблон пути без . и .. и внутри {}';
70
+ let depth = 0;
71
+ for (const c of pattern) {
72
+ if (c === '{' && ++depth > 1)
73
+ return 'вложенные {} в шаблоне не поддерживаются';
74
+ if (c === '}' && --depth < 0)
75
+ return 'непарная } в шаблоне';
76
+ }
77
+ if (depth)
78
+ return 'непарная { в шаблоне';
79
+ return undefined;
80
+ }
81
+ const gatePathPattern = z
82
+ .string()
83
+ .min(1)
84
+ .max(200)
85
+ .superRefine((value, ctx) => {
86
+ const problem = gatePathPatternProblem(value);
87
+ if (problem)
88
+ ctx.addIssue({ code: 'custom', message: problem });
89
+ });
90
+ /**
91
+ * Условие применимости gate задачи: gate исполняется, только когда настоящий
92
+ * diff фазы (из Git, не заявление исполнителя) задевает один из путей или
93
+ * неявный вход gate; иначе пишется запись `not-applicable`, которая не PASS.
94
+ * Необязательное поле без умолчания: политика без него сохраняет digest.
95
+ */
96
+ export const gateWhenSchema = z.strictObject({
97
+ paths: z.array(gatePathPattern).min(1).max(64),
98
+ });
99
+ const gateWhen = gateWhenSchema.optional();
51
100
  export const gateSchema = z.discriminatedUnion('kind', [
52
101
  z.strictObject({
53
102
  ...gateCommon,
54
103
  kind: z.literal('test'),
55
104
  report: junitReport,
56
105
  artifacts: gateArtifacts,
106
+ when: gateWhen,
57
107
  }),
58
108
  z.strictObject({
59
109
  ...gateCommon,
60
110
  kind: z.literal('check'),
61
111
  report: junitReport.optional(),
62
112
  artifacts: gateArtifacts,
113
+ when: gateWhen,
63
114
  }),
64
115
  ]);
116
+ /**
117
+ * Digest определения gate задачи (с `when`): под ним записывается решение о
118
+ * применимости. Смена команды, путей или любого поля — другой digest.
119
+ */
120
+ export const gateDigest = (gate) => digestOf(gate);
65
121
  /** Группы gates: не больше 100 групп по 100 ссылок, члены — gates или группы (`@имя`). */
66
122
  export const gateGroupsSchema = z
67
123
  .record(idSchema, z.array(gateRefSchema).min(1).max(100))
@@ -494,6 +550,14 @@ export function policyIssues(policy) {
494
550
  gateChecks(repo.gates, ['repositories', r, 'gates']);
495
551
  if (!repo.gates.some((g) => g.kind === 'test'))
496
552
  add('INVALID_INPUT', ['repositories', r, 'gates'], 'Нужен хотя бы один test gate с JUnit report');
553
+ // Условие путей: хотя бы один test gate исполняется всегда, и генеративный
554
+ // gate условным не бывает (его seed и отчёт свойств — доказательство).
555
+ else if (!repo.gates.some((g) => g.kind === 'test' && !g.when))
556
+ add('INVALID_INPUT', ['repositories', r, 'gates'], 'Нужен хотя бы один test gate без when: все test gates не могут быть условными');
557
+ repo.gates.forEach((g, i) => {
558
+ if (g.when && g.property)
559
+ add('INVALID_INPUT', ['repositories', r, 'gates', i, 'when'], 'Генеративный gate (property) не может быть условным (when)');
560
+ });
497
561
  for (const group of Object.keys(repo.gateGroups ?? {}))
498
562
  try {
499
563
  expandGateRefs(repo, ['@' + group]);
@@ -223,6 +223,9 @@ export declare const resolvedProfileSchema: z.ZodObject<{
223
223
  path: z.ZodString;
224
224
  }, z.core.$strict>;
225
225
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
226
+ when: z.ZodOptional<z.ZodObject<{
227
+ paths: z.ZodArray<z.ZodString>;
228
+ }, z.core.$strict>>;
226
229
  id: z.ZodString;
227
230
  command: z.ZodArray<z.ZodString>;
228
231
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -239,6 +242,9 @@ export declare const resolvedProfileSchema: z.ZodObject<{
239
242
  path: z.ZodString;
240
243
  }, z.core.$strict>>;
241
244
  artifacts: z.ZodOptional<z.ZodArray<z.ZodString>>;
245
+ when: z.ZodOptional<z.ZodObject<{
246
+ paths: z.ZodArray<z.ZodString>;
247
+ }, z.core.$strict>>;
242
248
  id: z.ZodString;
243
249
  command: z.ZodArray<z.ZodString>;
244
250
  timeoutMs: z.ZodDefault<z.ZodNumber>;