kibi-core 0.21.1 → 0.22.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-core",
3
- "version": "0.21.1",
3
+ "version": "0.22.1",
4
4
  "private": false,
5
5
  "description": "Core Prolog modules and RDF graph logic for Kibi",
6
6
  "type": "module",
package/src/checks.pl CHANGED
@@ -9,6 +9,7 @@
9
9
  check_selected_json/2, % Returns only selected rule violations as JSON
10
10
  check_must_priority_coverage/1, % Returns list of must-priority violations
11
11
  check_symbol_coverage/1, % Returns list of uncovered symbols
12
+ check_changed_symbol_coverage/2, % symbol-coverage restricted to a staged change set
12
13
  check_symbol_traceability/2, % Returns list of symbols lacking requirement traceability (ReqAdr option)
13
14
  check_proof_contract_symbols/1, % Returns unresolved or unexpected required_proofs symbol issues
14
15
  check_no_dangling_refs/1, % Returns list of dangling ref violations
@@ -198,6 +199,18 @@ check_symbol_coverage(Violations) :-
198
199
  sort(SymbolIds0, SymbolIds),
199
200
  maplist(symbol_coverage_violation, SymbolIds, Violations).
200
201
 
202
+ %% check_changed_symbol_coverage(+ExtraSymbols, -Violations)
203
+ % The symbol-coverage rule for the staged gate: the same violations
204
+ % check_symbol_coverage/1 reports, restricted to the changed symbols
205
+ % (kb:changed_symbol/1 overlay facts plus ExtraSymbols).
206
+ % implements REQ-014
207
+ check_changed_symbol_coverage(ExtraSymbols, Violations) :-
208
+ findall(SymbolId,
209
+ changed_symbol_no_req_coverage(ExtraSymbols, SymbolId),
210
+ SymbolIds0),
211
+ sort(SymbolIds0, SymbolIds),
212
+ maplist(symbol_coverage_violation, SymbolIds, Violations).
213
+
201
214
  symbol_coverage_violation(SymbolId, violation(
202
215
  'symbol-coverage',
203
216
  SymbolId,
package/src/kb.pl CHANGED
@@ -61,6 +61,7 @@
61
61
  adr_chain/2,
62
62
  deprecated_no_successor/1,
63
63
  symbol_no_req_coverage/2,
64
+ changed_symbol_no_req_coverage/2,
64
65
  predicate_schema/6,
65
66
  predicate_schema_keys/4,
66
67
  predicate_fact/5,
@@ -2465,12 +2466,36 @@ coverage_gap(Req, missing_test) :-
2465
2466
  has_scenario(Req),
2466
2467
  \+ has_test(Req).
2467
2468
 
2469
+ % implements REQ-core-validation-rules
2470
+ % Only a current must-priority requirement owes scenario and test coverage.
2468
2471
  must_requirement(Req) :-
2469
2472
  kb_entity(Req, req, Props),
2470
2473
  memberchk(priority=Priority, Props),
2471
2474
  normalize_term_atom(Priority, PriorityAtom),
2472
2475
  atom_string(PriorityAtom, PriorityStr),
2473
- sub_string(PriorityStr, _, 4, 0, "must").
2476
+ sub_string(PriorityStr, _, 4, 0, "must"),
2477
+ coverage_current_requirement(Req, Props).
2478
+
2479
+ %% coverage_current_requirement(+Req, +Props)
2480
+ % A requirement is still owed coverage unless it is retired: superseded by
2481
+ % another requirement (the target of `supersedes`), carrying a retired status,
2482
+ % or `closed` without the `implemented` tag (a closed requirement is retired
2483
+ % work unless it records that it was implemented, the same rule the
2484
+ % coverage-depth review applies). A requirement without a status keeps the
2485
+ % obligation.
2486
+ coverage_current_requirement(Req, Props) :-
2487
+ \+ kb_relationship(supersedes, _, Req),
2488
+ ( memberchk(status=RawStatus, Props)
2489
+ -> normalize_term_atom(RawStatus, Status)
2490
+ ; Status = missing
2491
+ ),
2492
+ \+ memberchk(Status, [deprecated, superseded, archived, removed, deleted, rejected]),
2493
+ ( Status == closed
2494
+ -> memberchk(tags=RawTags, Props),
2495
+ normalize_term_atom_list(RawTags, Tags),
2496
+ memberchk(implemented, Tags)
2497
+ ; true
2498
+ ).
2474
2499
 
2475
2500
  has_scenario(Req) :-
2476
2501
  once(kb_relationship(specified_by, Req, _)).
@@ -3327,6 +3352,23 @@ changed_symbol_missing_req(Symbol, MinLinks, Count) :-
3327
3352
  length(UniqueReqs, Count),
3328
3353
  Count < MinLinks.
3329
3354
 
3355
+ %% changed_symbol_no_req_coverage(+ExtraSymbols, -Symbol)
3356
+ % The full-check symbol-coverage rule restricted to a staged change set: the
3357
+ % overlay changed_symbol/1 facts plus ExtraSymbols (symbols whose staged
3358
+ % manifest entry changed). It reuses symbol_no_req_coverage/2, so the staged
3359
+ % gate and `kibi check` judge coverage identically: a direct req->test edge
3360
+ % counts only while the requirement has no scenario.
3361
+ % implements REQ-014
3362
+ changed_symbol_no_req_coverage(ExtraSymbols, Symbol) :-
3363
+ findall(Candidate,
3364
+ ( changed_symbol(Candidate)
3365
+ ; member(Candidate, ExtraSymbols)
3366
+ ),
3367
+ Candidates0),
3368
+ sort(Candidates0, Candidates),
3369
+ member(Symbol, Candidates),
3370
+ symbol_no_req_coverage(Symbol, _).
3371
+
3330
3372
  %% changed_symbol_violation(+Symbol, +MinLinks, -Count, -File, -Line, -Col, -Name)
3331
3373
  % Full violation record for a changed symbol missing requirements.
3332
3374
  changed_symbol_violation(Symbol, MinLinks, Count, File, Line, Col, Name) :-
@@ -17,6 +17,7 @@
17
17
  known_rule('must-priority-coverage').
18
18
  known_rule('symbol-coverage').
19
19
  known_rule('symbol-traceability').
20
+ known_rule('symbol-granularity').
20
21
  known_rule('no-dangling-refs').
21
22
  known_rule('source-relationship-parity').
22
23
  known_rule('branch-store-not-compiled').
@@ -69,6 +70,7 @@ known_rule('policy-markers').
69
70
  rule_enforcement_class('must-priority-coverage', canonical).
70
71
  rule_enforcement_class('symbol-coverage', canonical).
71
72
  rule_enforcement_class('symbol-traceability', canonical).
73
+ rule_enforcement_class('symbol-granularity', canonical).
72
74
  rule_enforcement_class('no-dangling-refs', canonical).
73
75
  rule_enforcement_class('source-relationship-parity', canonical).
74
76
  rule_enforcement_class('branch-store-not-compiled', canonical).
@@ -121,6 +123,7 @@ rule_enforcement_class('policy-markers', canonical).
121
123
  rule_implementation('must-priority-coverage', prolog).
122
124
  rule_implementation('symbol-coverage', prolog).
123
125
  rule_implementation('symbol-traceability', prolog).
126
+ rule_implementation('symbol-granularity', typescript).
124
127
  rule_implementation('no-dangling-refs', prolog).
125
128
  rule_implementation('source-relationship-parity', typescript).
126
129
  rule_implementation('branch-store-not-compiled', typescript).
@@ -240,9 +243,10 @@ rule_predicate_arity('symbol-owner-superseded', 1).
240
243
  rule_predicate_arity('adr-unlinked', 1).
241
244
  rule_predicate_arity('adr-proposed', 1).
242
245
 
243
- rule_description('must-priority-coverage', 'Every must-priority requirement must have a scenario and a test').
246
+ rule_description('must-priority-coverage', 'Every current must-priority requirement (not superseded, retired, or closed without the implemented tag) must have a scenario and a test').
244
247
  rule_description('symbol-coverage', 'Production symbols need qualifying coverage via covered_by plus a canonical requirement/scenario test path').
245
248
  rule_description('symbol-traceability', 'Production symbols must directly implement requirements for ownership; covered_by is coverage only and executable_for is test identity only').
249
+ rule_description('symbol-granularity', 'A symbol with traceability relationships must not link its source file coarsely while narrower behavioral symbols are available, unless it carries an allowed granularity_reason; the staged gate\'s symbol_granularity_violation evaluated KB-wide').
246
250
  rule_description('no-dangling-refs', 'All relationship targets must exist in the KB').
247
251
  rule_description('source-relationship-parity', 'Authored Markdown and relationship-shard edges must exactly match the compiled KB').
248
252
  rule_description('branch-store-not-compiled', 'The current branch\'s KB store must be compiled from the authored .kb/ sources; a missing or empty store is reported once, naming kibi sync, instead of every store-backed rule reading an empty KB').