@agent-wiki/mcp 0.18.0 → 0.20.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.
Files changed (68) hide show
  1. package/dist/cobol/__tests__/call-boundary-lineage.test.js +576 -10
  2. package/dist/cobol/__tests__/call-boundary-lineage.test.js.map +1 -1
  3. package/dist/cobol/__tests__/db2-table-lineage.test.js +502 -13
  4. package/dist/cobol/__tests__/db2-table-lineage.test.js.map +1 -1
  5. package/dist/cobol/__tests__/extractors.test.js +110 -0
  6. package/dist/cobol/__tests__/extractors.test.js.map +1 -1
  7. package/dist/cobol/__tests__/field-lineage.test.js +127 -0
  8. package/dist/cobol/__tests__/field-lineage.test.js.map +1 -1
  9. package/dist/cobol/__tests__/lexer.test.js +42 -0
  10. package/dist/cobol/__tests__/lexer.test.js.map +1 -1
  11. package/dist/cobol/__tests__/variable-tracer.test.js +306 -0
  12. package/dist/cobol/__tests__/variable-tracer.test.js.map +1 -1
  13. package/dist/cobol/call-boundary-lineage.d.ts +53 -1
  14. package/dist/cobol/call-boundary-lineage.d.ts.map +1 -1
  15. package/dist/cobol/call-boundary-lineage.js +226 -13
  16. package/dist/cobol/call-boundary-lineage.js.map +1 -1
  17. package/dist/cobol/db2-table-lineage.d.ts +72 -1
  18. package/dist/cobol/db2-table-lineage.d.ts.map +1 -1
  19. package/dist/cobol/db2-table-lineage.js +210 -11
  20. package/dist/cobol/db2-table-lineage.js.map +1 -1
  21. package/dist/cobol/extractors.d.ts +8 -0
  22. package/dist/cobol/extractors.d.ts.map +1 -1
  23. package/dist/cobol/extractors.js +27 -11
  24. package/dist/cobol/extractors.js.map +1 -1
  25. package/dist/cobol/field-lineage.d.ts.map +1 -1
  26. package/dist/cobol/field-lineage.js +186 -36
  27. package/dist/cobol/field-lineage.js.map +1 -1
  28. package/dist/cobol/graph.d.ts +8 -0
  29. package/dist/cobol/graph.d.ts.map +1 -1
  30. package/dist/cobol/graph.js +10 -0
  31. package/dist/cobol/graph.js.map +1 -1
  32. package/dist/cobol/lexer.d.ts.map +1 -1
  33. package/dist/cobol/lexer.js +11 -0
  34. package/dist/cobol/lexer.js.map +1 -1
  35. package/dist/cobol/parser.d.ts.map +1 -1
  36. package/dist/cobol/parser.js +6 -0
  37. package/dist/cobol/parser.js.map +1 -1
  38. package/dist/cobol/plugin.d.ts.map +1 -1
  39. package/dist/cobol/plugin.js +14 -2
  40. package/dist/cobol/plugin.js.map +1 -1
  41. package/dist/cobol/types.d.ts +10 -0
  42. package/dist/cobol/types.d.ts.map +1 -1
  43. package/dist/cobol/variable-tracer.d.ts.map +1 -1
  44. package/dist/cobol/variable-tracer.js +100 -10
  45. package/dist/cobol/variable-tracer.js.map +1 -1
  46. package/dist/code-analysis.d.ts +8 -1
  47. package/dist/code-analysis.d.ts.map +1 -1
  48. package/dist/code-analysis.js.map +1 -1
  49. package/dist/evidence-migration.d.ts.map +1 -1
  50. package/dist/evidence-migration.js +15 -3
  51. package/dist/evidence-migration.js.map +1 -1
  52. package/dist/evidence-migration.test.js +4 -0
  53. package/dist/evidence-migration.test.js.map +1 -1
  54. package/dist/evidence-write-log.d.ts +21 -0
  55. package/dist/evidence-write-log.d.ts.map +1 -1
  56. package/dist/evidence-write-log.js.map +1 -1
  57. package/dist/server.d.ts.map +1 -1
  58. package/dist/server.js +85 -4
  59. package/dist/server.js.map +1 -1
  60. package/dist/server.test.js +31 -0
  61. package/dist/server.test.js.map +1 -1
  62. package/dist/wiki.d.ts +43 -0
  63. package/dist/wiki.d.ts.map +1 -1
  64. package/dist/wiki.js +85 -7
  65. package/dist/wiki.js.map +1 -1
  66. package/dist/wiki.test.js +255 -0
  67. package/dist/wiki.test.js.map +1 -1
  68. package/package.json +1 -1
@@ -125,7 +125,7 @@ describe("buildCallBoundLineage", () => {
125
125
  [1, "WS-B", "LK-B"],
126
126
  ]);
127
127
  });
128
- it("does not emit entries when USING arity differs from LINKAGE arity", () => {
128
+ it("emits arity-mismatch diagnostic when USING arity differs from LINKAGE arity", () => {
129
129
  const caller = `
130
130
  IDENTIFICATION DIVISION.
131
131
  PROGRAM-ID. CALLER.
@@ -154,9 +154,13 @@ describe("buildCallBoundLineage", () => {
154
154
  model(caller, "CALLER.cbl"),
155
155
  model(callee, "CALLEE.cbl"),
156
156
  ]);
157
- expect(lineage).toBeNull();
157
+ expect(lineage).not.toBeNull();
158
+ expect(lineage.entries).toHaveLength(0);
159
+ expect(lineage.diagnostics).toHaveLength(1);
160
+ expect(lineage.diagnostics[0].kind).toBe("arity-mismatch");
161
+ expect(lineage.diagnostics[0].target).toBe("CALLEE");
158
162
  });
159
- it("does not emit entries when scalar PICs differ", () => {
163
+ it("emits shape-mismatch diagnostic when scalar PICs differ", () => {
160
164
  const caller = `
161
165
  IDENTIFICATION DIVISION.
162
166
  PROGRAM-ID. CALLER.
@@ -184,9 +188,11 @@ describe("buildCallBoundLineage", () => {
184
188
  model(caller, "CALLER.cbl"),
185
189
  model(callee, "CALLEE.cbl"),
186
190
  ]);
187
- expect(lineage).toBeNull();
191
+ expect(lineage).not.toBeNull();
192
+ expect(lineage.entries).toHaveLength(0);
193
+ expect(lineage.diagnostics.map((d) => d.kind)).toEqual(["shape-mismatch"]);
188
194
  });
189
- it("does not emit entries when one side is a group and the other is a scalar", () => {
195
+ it("emits shape-mismatch diagnostic when one side is a group and the other is a scalar", () => {
190
196
  const caller = `
191
197
  IDENTIFICATION DIVISION.
192
198
  PROGRAM-ID. CALLER.
@@ -215,7 +221,9 @@ describe("buildCallBoundLineage", () => {
215
221
  model(caller, "CALLER.cbl"),
216
222
  model(callee, "CALLEE.cbl"),
217
223
  ]);
218
- expect(lineage).toBeNull();
224
+ expect(lineage).not.toBeNull();
225
+ expect(lineage.entries).toHaveLength(0);
226
+ expect(lineage.diagnostics.map((d) => d.kind)).toEqual(["shape-mismatch"]);
219
227
  });
220
228
  it("does not emit entries when callee is unresolved (no parsed program with that name)", () => {
221
229
  const lineage = buildCallBoundLineage([
@@ -223,7 +231,7 @@ describe("buildCallBoundLineage", () => {
223
231
  ]);
224
232
  expect(lineage).toBeNull();
225
233
  });
226
- it("does not emit entries for dynamic CALL where target is a variable", () => {
234
+ it("emits dynamic-call diagnostic when CALL target is a variable identifier", () => {
227
235
  const caller = `
228
236
  IDENTIFICATION DIVISION.
229
237
  PROGRAM-ID. CALLER.
@@ -242,9 +250,90 @@ describe("buildCallBoundLineage", () => {
242
250
  model(caller, "CALLER.cbl"),
243
251
  model(calleeWithLinkageGroup, "CALLEE.cbl"),
244
252
  ]);
245
- expect(lineage).toBeNull();
253
+ expect(lineage).not.toBeNull();
254
+ expect(lineage.entries).toHaveLength(0);
255
+ expect(lineage.diagnostics.map((d) => d.kind)).toEqual(["dynamic-call"]);
256
+ expect(lineage.diagnostics[0].target).toBe("WS-PROG-NAME");
257
+ });
258
+ it("attaches a weak/inferred envelope to high-confidence entries (name divergence)", () => {
259
+ // Top-level group pair matches deterministically; descended children
260
+ // have divergent names → child entries are confidence: "high" → envelope
261
+ // should be weak/inferred.
262
+ const callerSrc = `
263
+ IDENTIFICATION DIVISION.
264
+ PROGRAM-ID. CALLER.
265
+ DATA DIVISION.
266
+ WORKING-STORAGE SECTION.
267
+ 01 WS-REC.
268
+ 05 WS-FOO PIC X(5).
269
+ PROCEDURE DIVISION.
270
+ A000-MAIN SECTION.
271
+ A100-START.
272
+ CALL "CALLEE" USING WS-REC.
273
+ STOP RUN.
274
+ `;
275
+ const calleeSrc = `
276
+ IDENTIFICATION DIVISION.
277
+ PROGRAM-ID. CALLEE.
278
+ DATA DIVISION.
279
+ LINKAGE SECTION.
280
+ 01 LK-REC.
281
+ 05 LK-COMPLETELY-OTHER-NAME PIC X(5).
282
+ PROCEDURE DIVISION USING LK-REC.
283
+ A000-MAIN SECTION.
284
+ A100-START.
285
+ GOBACK.
286
+ `;
287
+ const lineage = buildCallBoundLineage([
288
+ model(callerSrc, "CALLER.cbl"),
289
+ model(calleeSrc, "CALLEE.cbl"),
290
+ ]);
291
+ expect(lineage).not.toBeNull();
292
+ const child = lineage.entries.find((e) => e.confidence === "high");
293
+ expect(child).toBeDefined();
294
+ expect(child.envelope.confidence).toBe("weak");
295
+ expect(child.envelope.basis).toBe("inferred");
296
+ expect(child.envelope.abstain).toBe(false);
246
297
  });
247
- it("does not emit entries when caller's USING arg is not a top-level data item", () => {
298
+ it("attaches an EvidenceEnvelope to each entry derived from confidence tier", () => {
299
+ const callerSrc = `
300
+ IDENTIFICATION DIVISION.
301
+ PROGRAM-ID. CALLER.
302
+ DATA DIVISION.
303
+ WORKING-STORAGE SECTION.
304
+ 01 WS-A PIC X(5).
305
+ PROCEDURE DIVISION.
306
+ A000-MAIN SECTION.
307
+ A100-START.
308
+ CALL "CALLEE" USING WS-A.
309
+ STOP RUN.
310
+ `;
311
+ const calleeSrc = `
312
+ IDENTIFICATION DIVISION.
313
+ PROGRAM-ID. CALLEE.
314
+ DATA DIVISION.
315
+ LINKAGE SECTION.
316
+ 01 LK-A PIC X(5).
317
+ PROCEDURE DIVISION USING LK-A.
318
+ A000-MAIN SECTION.
319
+ A100-START.
320
+ GOBACK.
321
+ `;
322
+ const lineage = buildCallBoundLineage([
323
+ model(callerSrc, "CALLER.cbl"),
324
+ model(calleeSrc, "CALLEE.cbl"),
325
+ ]);
326
+ expect(lineage).not.toBeNull();
327
+ const entry = lineage.entries[0];
328
+ expect(entry.envelope.confidence).toBe("strong");
329
+ expect(entry.envelope.basis).toBe("deterministic");
330
+ expect(entry.envelope.abstain).toBe(false);
331
+ expect(entry.envelope.provenance).toEqual([
332
+ { raw: "CALLER.cbl", line: expect.any(Number) },
333
+ { raw: "CALLEE.cbl" },
334
+ ]);
335
+ });
336
+ it("emits caller-arg-not-top-level diagnostic when USING arg is nested", () => {
248
337
  const caller = `
249
338
  IDENTIFICATION DIVISION.
250
339
  PROGRAM-ID. CALLER.
@@ -273,7 +362,9 @@ describe("buildCallBoundLineage", () => {
273
362
  model(caller, "CALLER.cbl"),
274
363
  model(callee, "CALLEE.cbl"),
275
364
  ]);
276
- expect(lineage).toBeNull();
365
+ expect(lineage).not.toBeNull();
366
+ expect(lineage.entries).toHaveLength(0);
367
+ expect(lineage.diagnostics.map((d) => d.kind)).toEqual(["caller-arg-not-top-level"]);
277
368
  });
278
369
  it("does not emit entries when CALL has no USING clause", () => {
279
370
  const caller = `
@@ -501,5 +592,480 @@ describe("buildCallBoundLineage", () => {
501
592
  .sort();
502
593
  expect(childNames).toEqual(["WS-A", "WS-B"]);
503
594
  });
595
+ it("classifies CALL of an IBM runtime API as system-call, not unresolved-callee (#26 phase 1)", () => {
596
+ // CALL to an IBM-published runtime (MQ / Language Environment / CICS
597
+ // batch family) shouldn't be reported as a missing user program. The
598
+ // SYSTEM_CALLEES whitelist routes these to a dedicated `system-call`
599
+ // diagnostic so the noise floor stays low and genuine user-program
600
+ // gaps stand out.
601
+ const caller = `
602
+ IDENTIFICATION DIVISION.
603
+ PROGRAM-ID. CALLER.
604
+ DATA DIVISION.
605
+ WORKING-STORAGE SECTION.
606
+ 01 WS-MQ-HCONN PIC 9(9).
607
+ 01 WS-MQ-OPTIONS PIC 9(9).
608
+ PROCEDURE DIVISION.
609
+ A000-MAIN SECTION.
610
+ A100-START.
611
+ CALL "MQCONN" USING WS-MQ-HCONN WS-MQ-OPTIONS.
612
+ CALL "CEEDATE" USING WS-MQ-HCONN WS-MQ-OPTIONS.
613
+ STOP RUN.
614
+ `;
615
+ // Need a second user program in the corpus so the analyzer doesn't
616
+ // bail at the < 2 programs guard.
617
+ const otherUser = `
618
+ IDENTIFICATION DIVISION.
619
+ PROGRAM-ID. OTHER.
620
+ DATA DIVISION.
621
+ LINKAGE SECTION.
622
+ 01 LK-X PIC X(8).
623
+ PROCEDURE DIVISION USING LK-X.
624
+ A000-MAIN SECTION.
625
+ A100-START.
626
+ GOBACK.
627
+ `;
628
+ const lineage = buildCallBoundLineage([
629
+ model(caller, "CALLER.cbl"),
630
+ model(otherUser, "OTHER.cbl"),
631
+ ]);
632
+ expect(lineage).not.toBeNull();
633
+ const systemCalls = lineage.diagnostics.filter((d) => d.kind === "system-call");
634
+ expect(systemCalls).toHaveLength(2);
635
+ expect(systemCalls.map((d) => d.target).sort()).toEqual(["CEEDATE", "MQCONN"]);
636
+ // The IBM-API targets do NOT show up as unresolved-callee.
637
+ const unresolved = lineage.diagnostics.filter((d) => d.kind === "unresolved-callee");
638
+ expect(unresolved.some((d) => d.target === "MQCONN" || d.target === "CEEDATE")).toBe(false);
639
+ // Rationale points the user at the IBM-runtime classification.
640
+ expect(systemCalls[0].rationale).toContain("IBM");
641
+ // Summary count is updated.
642
+ expect(lineage.summary.diagnosticsByKind["system-call"]).toBe(2);
643
+ });
644
+ it("resolves USING arg defined in a COPY'd copybook (#26 phase 3)", () => {
645
+ // Phase 3: parser doesn't inline-expand COPY, so a `01 TEST-RECORD`
646
+ // declared inside a copybook never appears in `caller.dataItems`.
647
+ // Pre-fix the analyzer fired `caller-arg-not-top-level` for every
648
+ // COPY-supplied USING arg. With the copybook fallback, the resolver
649
+ // walks the parsed copybooks the caller COPYs and finds the record.
650
+ const copybook = `
651
+ 01 TEST-RECORD.
652
+ 05 FIELD-A PIC X(10).
653
+ 05 FIELD-B PIC 9(5).
654
+ `;
655
+ const caller = `
656
+ IDENTIFICATION DIVISION.
657
+ PROGRAM-ID. CALLER01.
658
+ DATA DIVISION.
659
+ WORKING-STORAGE SECTION.
660
+ COPY TESTREC.
661
+ PROCEDURE DIVISION.
662
+ A100.
663
+ CALL "CALLEE01" USING TEST-RECORD.
664
+ STOP RUN.
665
+ `;
666
+ const callee = `
667
+ IDENTIFICATION DIVISION.
668
+ PROGRAM-ID. CALLEE01.
669
+ DATA DIVISION.
670
+ LINKAGE SECTION.
671
+ 01 LK-RECORD.
672
+ 05 LK-FIELD-A PIC X(10).
673
+ 05 LK-FIELD-B PIC 9(5).
674
+ PROCEDURE DIVISION USING LK-RECORD.
675
+ A100.
676
+ GOBACK.
677
+ `;
678
+ const lineage = buildCallBoundLineage([
679
+ model(copybook, "TESTREC.cpy"),
680
+ model(caller, "CALLER01.cbl"),
681
+ model(callee, "CALLEE01.cbl"),
682
+ ]);
683
+ expect(lineage).not.toBeNull();
684
+ // No caller-arg-not-top-level diagnostic — copybook fallback resolves it.
685
+ expect(lineage.diagnostics.some((d) => d.kind === "caller-arg-not-top-level")).toBe(false);
686
+ // Pair succeeds.
687
+ expect(lineage.entries.length).toBeGreaterThan(0);
688
+ const topPair = lineage.entries.find((e) => e.position === 0);
689
+ expect(topPair?.caller.fieldName).toBe("TEST-RECORD");
690
+ });
691
+ it("inline data item shadows a same-named copybook item (#26 phase 3 precedence)", () => {
692
+ // Resolution order: caller's own dataItems first, then copybooks.
693
+ // A program declaring `01 TEST-RECORD` inline AND copying a
694
+ // copybook with the same name uses the inline declaration.
695
+ const copybook = `
696
+ 01 TEST-RECORD.
697
+ 05 CPY-FIELD PIC X(99).
698
+ `;
699
+ const caller = `
700
+ IDENTIFICATION DIVISION.
701
+ PROGRAM-ID. CALLER02.
702
+ DATA DIVISION.
703
+ WORKING-STORAGE SECTION.
704
+ 01 TEST-RECORD.
705
+ 05 WS-FIELD PIC X(10).
706
+ COPY TESTREC.
707
+ PROCEDURE DIVISION.
708
+ A100.
709
+ CALL "CALLEE02" USING TEST-RECORD.
710
+ STOP RUN.
711
+ `;
712
+ const callee = `
713
+ IDENTIFICATION DIVISION.
714
+ PROGRAM-ID. CALLEE02.
715
+ DATA DIVISION.
716
+ LINKAGE SECTION.
717
+ 01 LK-RECORD.
718
+ 05 LK-FIELD PIC X(10).
719
+ PROCEDURE DIVISION USING LK-RECORD.
720
+ A100.
721
+ GOBACK.
722
+ `;
723
+ const lineage = buildCallBoundLineage([
724
+ model(copybook, "TESTREC.cpy"),
725
+ model(caller, "CALLER02.cbl"),
726
+ model(callee, "CALLEE02.cbl"),
727
+ ]);
728
+ expect(lineage).not.toBeNull();
729
+ const topPair = lineage.entries.find((e) => e.position === 0);
730
+ // The pair child count reflects the INLINE TEST-RECORD (1 child:
731
+ // WS-FIELD), not the copybook's TEST-RECORD (1 child: CPY-FIELD).
732
+ // Since both have 1 child the count is the same; what differs is
733
+ // which child name surfaces in nested pairs.
734
+ expect(topPair).toBeDefined();
735
+ const childPair = lineage.entries.find((e) => e.position === 0 && e.caller.fieldName === "WS-FIELD");
736
+ expect(childPair).toBeDefined();
737
+ });
738
+ it("CICS DFHCOMMAREA: caller's single USING arg pairs with DFHCOMMAREA when callee has multiple LINKAGE records (#26 phase 4)", () => {
739
+ // Realistic CICS program shape: LINKAGE declares both the implicit
740
+ // DFHCOMMAREA and additional work records. Pre-fix the analyzer
741
+ // compared raw linkage count (>1) against caller's single USING arg
742
+ // and fired a false `arity-mismatch`. Phase 4 narrows the effective
743
+ // linkage to just DFHCOMMAREA in this case (the CICS convention).
744
+ const cicsCallee = `
745
+ IDENTIFICATION DIVISION.
746
+ PROGRAM-ID. CICSCALEE.
747
+ DATA DIVISION.
748
+ LINKAGE SECTION.
749
+ 01 DFHCOMMAREA.
750
+ 05 COMM-FIELD PIC X(20).
751
+ 01 LK-EXTRA.
752
+ 05 EXTRA-FIELD PIC X(10).
753
+ PROCEDURE DIVISION.
754
+ GOBACK.
755
+ `;
756
+ const caller = `
757
+ IDENTIFICATION DIVISION.
758
+ PROGRAM-ID. CALLER.
759
+ DATA DIVISION.
760
+ WORKING-STORAGE SECTION.
761
+ 01 WS-COMM-RECORD.
762
+ 05 WS-COMM-FIELD PIC X(20).
763
+ PROCEDURE DIVISION.
764
+ A100.
765
+ CALL "CICSCALEE" USING WS-COMM-RECORD.
766
+ STOP RUN.
767
+ `;
768
+ const lineage = buildCallBoundLineage([
769
+ model(cicsCallee, "CICSCALEE.cbl"),
770
+ model(caller, "CALLER.cbl"),
771
+ ]);
772
+ expect(lineage).not.toBeNull();
773
+ // No arity-mismatch; pair succeeds with DFHCOMMAREA.
774
+ expect(lineage.diagnostics.some((d) => d.kind === "arity-mismatch")).toBe(false);
775
+ expect(lineage.entries.length).toBeGreaterThan(0);
776
+ // Pair callee side is DFHCOMMAREA, not LK-EXTRA.
777
+ const topEntry = lineage.entries.find((e) => e.position === 0);
778
+ expect(topEntry?.callee.fieldName).toBe("DFHCOMMAREA");
779
+ });
780
+ it("CICS DFHCOMMAREA: simple single-LINKAGE case still works (no regression #26 phase 4)", () => {
781
+ // The single-DFHCOMMAREA case worked pre-fix (arity matches at 1=1).
782
+ // Verify the Phase 4 fallthrough doesn't break it.
783
+ const cicsCallee = `
784
+ IDENTIFICATION DIVISION.
785
+ PROGRAM-ID. CICSCALEE.
786
+ DATA DIVISION.
787
+ LINKAGE SECTION.
788
+ 01 DFHCOMMAREA.
789
+ 05 COMM-FIELD PIC X(20).
790
+ PROCEDURE DIVISION.
791
+ GOBACK.
792
+ `;
793
+ const caller = `
794
+ IDENTIFICATION DIVISION.
795
+ PROGRAM-ID. CALLER.
796
+ DATA DIVISION.
797
+ WORKING-STORAGE SECTION.
798
+ 01 WS-COMM-RECORD.
799
+ 05 WS-COMM-FIELD PIC X(20).
800
+ PROCEDURE DIVISION.
801
+ A100.
802
+ CALL "CICSCALEE" USING WS-COMM-RECORD.
803
+ STOP RUN.
804
+ `;
805
+ const lineage = buildCallBoundLineage([
806
+ model(cicsCallee, "CICSCALEE.cbl"),
807
+ model(caller, "CALLER.cbl"),
808
+ ]);
809
+ expect(lineage).not.toBeNull();
810
+ expect(lineage.diagnostics.filter((d) => d.kind === "arity-mismatch")).toHaveLength(0);
811
+ expect(lineage.entries.length).toBeGreaterThan(0);
812
+ });
813
+ it("CICS DFHCOMMAREA: 2-arg caller does NOT trigger DFHCOMMAREA narrowing (#26 phase 4)", () => {
814
+ // Phase 4 only applies when caller passes exactly 1 arg. If the
815
+ // caller passes multiple args, the standard pair-by-position
816
+ // handling runs (and may surface a real arity-mismatch).
817
+ const cicsCallee = `
818
+ IDENTIFICATION DIVISION.
819
+ PROGRAM-ID. CICSCALEE.
820
+ DATA DIVISION.
821
+ LINKAGE SECTION.
822
+ 01 DFHCOMMAREA.
823
+ 05 COMM-FIELD PIC X(20).
824
+ 01 LK-EXTRA.
825
+ 05 EXTRA-FIELD PIC X(10).
826
+ PROCEDURE DIVISION.
827
+ GOBACK.
828
+ `;
829
+ const caller = `
830
+ IDENTIFICATION DIVISION.
831
+ PROGRAM-ID. CALLER.
832
+ DATA DIVISION.
833
+ WORKING-STORAGE SECTION.
834
+ 01 WS-A PIC X(20).
835
+ 01 WS-B PIC X(10).
836
+ 01 WS-C PIC X(5).
837
+ PROCEDURE DIVISION.
838
+ A100.
839
+ CALL "CICSCALEE" USING WS-A WS-B WS-C.
840
+ STOP RUN.
841
+ `;
842
+ const lineage = buildCallBoundLineage([
843
+ model(cicsCallee, "CICSCALEE.cbl"),
844
+ model(caller, "CALLER.cbl"),
845
+ ]);
846
+ // 3 args vs 2 LINKAGE records → real arity-mismatch, narrowing
847
+ // doesn't apply.
848
+ expect(lineage.diagnostics.some((d) => d.kind === "arity-mismatch")).toBe(true);
849
+ });
850
+ it("project-local extraSystemCallees option promotes additional names to system-call (#26 phase 2)", () => {
851
+ // Phase 2: site-specific runtime libraries shouldn't go in the
852
+ // open-source whitelist, but should be classifiable as system-call
853
+ // by callers passing a project-local extension list (loaded from a
854
+ // gitignored `.agent-wiki.local.yaml`). Synthetic placeholder name
855
+ // `YOURRTN1` stands in for what would be a real site runtime in
856
+ // production.
857
+ const caller = `
858
+ IDENTIFICATION DIVISION.
859
+ PROGRAM-ID. CALLER.
860
+ DATA DIVISION.
861
+ WORKING-STORAGE SECTION.
862
+ 01 WS-A PIC X(8).
863
+ PROCEDURE DIVISION.
864
+ A100.
865
+ CALL "YOURRTN1" USING WS-A.
866
+ STOP RUN.
867
+ `;
868
+ const otherUser = `
869
+ IDENTIFICATION DIVISION.
870
+ PROGRAM-ID. OTHER.
871
+ DATA DIVISION.
872
+ LINKAGE SECTION.
873
+ 01 LK-X PIC X(8).
874
+ PROCEDURE DIVISION USING LK-X.
875
+ A100.
876
+ GOBACK.
877
+ `;
878
+ const models = [
879
+ model(caller, "CALLER.cbl"),
880
+ model(otherUser, "OTHER.cbl"),
881
+ ];
882
+ // Without the option: YOURRTN1 is treated as missing user program.
883
+ const lineageDefault = buildCallBoundLineage(models);
884
+ expect(lineageDefault.diagnostics.some((d) => d.kind === "unresolved-callee" && d.target === "YOURRTN1")).toBe(true);
885
+ // With the option: YOURRTN1 is reclassified as system-call.
886
+ const lineageWithExtra = buildCallBoundLineage(models, {
887
+ extraSystemCallees: ["YOURRTN1"],
888
+ });
889
+ expect(lineageWithExtra.diagnostics.some((d) => d.kind === "system-call" && d.target === "YOURRTN1")).toBe(true);
890
+ expect(lineageWithExtra.diagnostics.some((d) => d.kind === "unresolved-callee" && d.target === "YOURRTN1")).toBe(false);
891
+ });
892
+ it("extraSystemCallees is case-insensitive — array input (#26 phase 2)", () => {
893
+ // Caller-passed names are uppercased before matching, so the
894
+ // local-config can use any case convention without affecting
895
+ // detection.
896
+ const caller = `
897
+ IDENTIFICATION DIVISION.
898
+ PROGRAM-ID. CALLER.
899
+ DATA DIVISION.
900
+ WORKING-STORAGE SECTION.
901
+ 01 WS-A PIC X(8).
902
+ PROCEDURE DIVISION.
903
+ A100.
904
+ CALL "MIXEDCASE" USING WS-A.
905
+ STOP RUN.
906
+ `;
907
+ const otherUser = `
908
+ IDENTIFICATION DIVISION.
909
+ PROGRAM-ID. OTHER.
910
+ DATA DIVISION.
911
+ LINKAGE SECTION.
912
+ 01 LK-X PIC X(8).
913
+ PROCEDURE DIVISION USING LK-X.
914
+ A100.
915
+ GOBACK.
916
+ `;
917
+ const lineage = buildCallBoundLineage([model(caller, "CALLER.cbl"), model(otherUser, "OTHER.cbl")], { extraSystemCallees: ["mixedcase"] });
918
+ const sysCall = lineage.diagnostics.find((d) => d.kind === "system-call" && d.target === "MIXEDCASE");
919
+ expect(sysCall).toBeDefined();
920
+ // Phase 2 rationale split: project-local extension has its own text,
921
+ // distinct from the IBM-whitelist branch.
922
+ expect(sysCall.rationale).toContain("project-local system-call extension");
923
+ expect(sysCall.rationale).not.toContain("IBM");
924
+ });
925
+ it("extraSystemCallees accepts spread-from-Set input via uppercase normalization (#26 phase 2)", () => {
926
+ // Caller has a Set in hand (e.g., already-deduped config). Spreading
927
+ // it into an array still yields correct case-insensitive matching.
928
+ const caller = `
929
+ IDENTIFICATION DIVISION.
930
+ PROGRAM-ID. CALLER.
931
+ DATA DIVISION.
932
+ WORKING-STORAGE SECTION.
933
+ 01 WS-A PIC X(8).
934
+ PROCEDURE DIVISION.
935
+ A100.
936
+ CALL "SETCASE" USING WS-A.
937
+ STOP RUN.
938
+ `;
939
+ const otherUser = `
940
+ IDENTIFICATION DIVISION.
941
+ PROGRAM-ID. OTHER.
942
+ DATA DIVISION.
943
+ LINKAGE SECTION.
944
+ 01 LK-X PIC X(8).
945
+ PROCEDURE DIVISION USING LK-X.
946
+ A100.
947
+ GOBACK.
948
+ `;
949
+ const lineage = buildCallBoundLineage([model(caller, "CALLER.cbl"), model(otherUser, "OTHER.cbl")], { extraSystemCallees: [...new Set(["setcase"])] });
950
+ expect(lineage.diagnostics.some((d) => d.kind === "system-call" && d.target === "SETCASE")).toBe(true);
951
+ });
952
+ it("system-call rationale on IBM-whitelist match retains IBM-specific attribution (#26 phase 1)", () => {
953
+ // IBM-whitelist branch and project-local extension branch produce
954
+ // different rationale text so users can tell which classification
955
+ // path matched.
956
+ const caller = `
957
+ IDENTIFICATION DIVISION.
958
+ PROGRAM-ID. CALLER.
959
+ DATA DIVISION.
960
+ WORKING-STORAGE SECTION.
961
+ 01 WS-A PIC X(8).
962
+ PROCEDURE DIVISION.
963
+ A100.
964
+ CALL "MQCONN" USING WS-A.
965
+ STOP RUN.
966
+ `;
967
+ const otherUser = `
968
+ IDENTIFICATION DIVISION.
969
+ PROGRAM-ID. OTHER.
970
+ DATA DIVISION.
971
+ LINKAGE SECTION.
972
+ 01 LK-X PIC X(8).
973
+ PROCEDURE DIVISION USING LK-X.
974
+ A100.
975
+ GOBACK.
976
+ `;
977
+ const lineage = buildCallBoundLineage([
978
+ model(caller, "CALLER.cbl"),
979
+ model(otherUser, "OTHER.cbl"),
980
+ ]);
981
+ const sysCall = lineage.diagnostics.find((d) => d.kind === "system-call" && d.target === "MQCONN");
982
+ expect(sysCall).toBeDefined();
983
+ expect(sysCall.rationale).toContain("IBM");
984
+ expect(sysCall.rationale).not.toContain("project-local");
985
+ });
986
+ it("Phase 3 copybook resolver is deterministic across input orders for duplicate canonical names", () => {
987
+ // Two copybook files share the basename TESTREC.cpy from different
988
+ // directories. The map sort by sourceFile should produce the same
989
+ // resolution regardless of the input array order.
990
+ const cpyA = `
991
+ 01 TEST-RECORD.
992
+ 05 FIELD-V1 PIC X(10).
993
+ `;
994
+ const cpyB = `
995
+ 01 TEST-RECORD.
996
+ 05 FIELD-V2 PIC X(99).
997
+ `;
998
+ const caller = `
999
+ IDENTIFICATION DIVISION.
1000
+ PROGRAM-ID. CALLER.
1001
+ DATA DIVISION.
1002
+ WORKING-STORAGE SECTION.
1003
+ COPY TESTREC.
1004
+ PROCEDURE DIVISION.
1005
+ A100.
1006
+ CALL "CALLEE" USING TEST-RECORD.
1007
+ STOP RUN.
1008
+ `;
1009
+ const callee = `
1010
+ IDENTIFICATION DIVISION.
1011
+ PROGRAM-ID. CALLEE.
1012
+ DATA DIVISION.
1013
+ LINKAGE SECTION.
1014
+ 01 LK-RECORD.
1015
+ 05 LK-FIELD PIC X(10).
1016
+ PROCEDURE DIVISION USING LK-RECORD.
1017
+ A100.
1018
+ GOBACK.
1019
+ `;
1020
+ const a = model(cpyA, "dir-a/TESTREC.cpy");
1021
+ const b = model(cpyB, "dir-b/TESTREC.cpy");
1022
+ const c = model(caller, "CALLER.cbl");
1023
+ const d = model(callee, "CALLEE.cbl");
1024
+ const findChildName = (lineage) => lineage?.entries.find((e) => e.position === 0 && e.caller.fieldName !== "TEST-RECORD")?.caller.fieldName;
1025
+ const lineage1 = buildCallBoundLineage([a, b, c, d]);
1026
+ const lineage2 = buildCallBoundLineage([b, a, c, d]);
1027
+ // Both orders should resolve to the same copybook variant.
1028
+ // dir-a sorts before dir-b → FIELD-V1 wins deterministically.
1029
+ expect(findChildName(lineage1)).toBe("FIELD-V1");
1030
+ expect(findChildName(lineage2)).toBe("FIELD-V1");
1031
+ });
1032
+ it("dynamic CALL <var> resolving to an IBM API name does NOT match the whitelist (#26 phase 1)", () => {
1033
+ // The whitelist is gated behind targetKind === "literal" — a runtime-
1034
+ // resolved CALL <variable> stays a dynamic-call diagnostic regardless
1035
+ // of whether the value at the call site happens to match an IBM API
1036
+ // name. Static lineage can't see the variable's runtime value.
1037
+ const caller = `
1038
+ IDENTIFICATION DIVISION.
1039
+ PROGRAM-ID. CALLER.
1040
+ DATA DIVISION.
1041
+ WORKING-STORAGE SECTION.
1042
+ 01 WS-PROG-NAME PIC X(8).
1043
+ 01 WS-A PIC X(8).
1044
+ PROCEDURE DIVISION.
1045
+ A000-MAIN SECTION.
1046
+ A100-START.
1047
+ MOVE "MQCONN" TO WS-PROG-NAME.
1048
+ CALL WS-PROG-NAME USING WS-A.
1049
+ STOP RUN.
1050
+ `;
1051
+ const otherUser = `
1052
+ IDENTIFICATION DIVISION.
1053
+ PROGRAM-ID. OTHER.
1054
+ DATA DIVISION.
1055
+ LINKAGE SECTION.
1056
+ 01 LK-X PIC X(8).
1057
+ PROCEDURE DIVISION USING LK-X.
1058
+ A000-MAIN SECTION.
1059
+ A100-START.
1060
+ GOBACK.
1061
+ `;
1062
+ const lineage = buildCallBoundLineage([
1063
+ model(caller, "CALLER.cbl"),
1064
+ model(otherUser, "OTHER.cbl"),
1065
+ ]);
1066
+ expect(lineage).not.toBeNull();
1067
+ expect(lineage.diagnostics.some((d) => d.kind === "system-call")).toBe(false);
1068
+ expect(lineage.diagnostics.some((d) => d.kind === "dynamic-call")).toBe(true);
1069
+ });
504
1070
  });
505
1071
  //# sourceMappingURL=call-boundary-lineage.test.js.map