@agent-wiki/mcp 0.21.0 → 0.21.3

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.
@@ -2415,6 +2415,188 @@ Content for backward compatibility test.`);
2415
2415
  await expect(handleTool(wiki, "code_impact", { node_id: "program:MISSING" })).rejects.toThrow(/not found/i);
2416
2416
  });
2417
2417
  });
2418
+ describe("evidence envelope coverage: raw_* and code_* tools", () => {
2419
+ beforeEach(cleanUp);
2420
+ afterEach(cleanUp);
2421
+ it("raw_read text response carries strong/deterministic envelope", async () => {
2422
+ const wiki = freshWiki();
2423
+ wiki.rawAdd("hello.txt", { content: "hello world" });
2424
+ const result = JSON.parse((await handleTool(wiki, "raw_read", { filename: "hello.txt" })));
2425
+ expect(result.evidence).toBeDefined();
2426
+ expect(result.evidence.confidence).toBe("strong");
2427
+ expect(result.evidence.basis).toBe("deterministic");
2428
+ expect(result.evidence.abstain).toBe(false);
2429
+ expect(result.evidence.provenance).toEqual([{ raw: "hello.txt" }]);
2430
+ });
2431
+ it("raw_read image response carries envelope in the text content block", async () => {
2432
+ const wiki = freshWiki();
2433
+ const pngBytes = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
2434
+ const rawPath = join(wiki.config.rawDir, "envpixel.png");
2435
+ writeFileSync(rawPath, pngBytes);
2436
+ writeFileSync(rawPath + ".meta.yaml", 'path: envpixel.png\ndownloadedAt: "2026-05-01"\nsha256: abcd\nsize: 4\nmimeType: image/png\n');
2437
+ const result = await handleTool(wiki, "raw_read", { filename: "envpixel.png" });
2438
+ expect(Array.isArray(result)).toBe(true);
2439
+ const blocks = result;
2440
+ const meta = JSON.parse(blocks[0].text);
2441
+ expect(meta.evidence.confidence).toBe("strong");
2442
+ expect(meta.evidence.basis).toBe("deterministic");
2443
+ expect(meta.evidence.provenance).toEqual([{ raw: "envpixel.png" }]);
2444
+ });
2445
+ it("raw_coverage response carries strong/deterministic envelope", async () => {
2446
+ const wiki = freshWiki();
2447
+ wiki.rawAdd("a.pdf", { content: "x" });
2448
+ wiki.write("p.md", "---\ntitle: P\nsources: [raw/a.pdf]\n---\n");
2449
+ const result = JSON.parse((await handleTool(wiki, "raw_coverage", {})));
2450
+ expect(result.evidence.confidence).toBe("strong");
2451
+ expect(result.evidence.basis).toBe("deterministic");
2452
+ expect(result.evidence.abstain).toBe(false);
2453
+ expect(result.evidence.rationale).toMatch(/SHA-256/);
2454
+ expect(result.evidence.provenance).toEqual([]);
2455
+ });
2456
+ it("code_parse response carries strong/deterministic envelope with raw provenance", async () => {
2457
+ const wiki = freshWiki();
2458
+ const cobol = ` IDENTIFICATION DIVISION.
2459
+ PROGRAM-ID. ENVPARSE.
2460
+ PROCEDURE DIVISION.
2461
+ STOP RUN.`;
2462
+ wiki.rawAdd("ENVPARSE.cbl", { content: cobol });
2463
+ const result = JSON.parse((await handleTool(wiki, "code_parse", { path: "ENVPARSE.cbl" })));
2464
+ expect(result.evidence.confidence).toBe("strong");
2465
+ expect(result.evidence.basis).toBe("deterministic");
2466
+ expect(result.evidence.abstain).toBe(false);
2467
+ expect(result.evidence.provenance).toEqual([{ raw: "ENVPARSE.cbl" }]);
2468
+ expect(result.evidence.rationale).toMatch(/Parsed ENVPARSE\.cbl/);
2469
+ });
2470
+ it("code_procedure_flow envelope is strong when procedures exist", async () => {
2471
+ const wiki = freshWiki();
2472
+ const cobol = ` IDENTIFICATION DIVISION.
2473
+ PROGRAM-ID. ENVFLOW.
2474
+ PROCEDURE DIVISION.
2475
+ 1000-MAIN SECTION.
2476
+ DISPLAY 'X'.
2477
+ STOP RUN.`;
2478
+ wiki.rawAdd("ENVFLOW.cbl", { content: cobol });
2479
+ await handleTool(wiki, "code_parse", { path: "ENVFLOW.cbl" });
2480
+ const result = JSON.parse((await handleTool(wiki, "code_procedure_flow", { path: "ENVFLOW.cbl" })));
2481
+ expect(result.evidence.confidence).toBe("strong");
2482
+ expect(result.evidence.abstain).toBe(false);
2483
+ expect(result.evidence.provenance).toEqual([{ raw: "ENVFLOW.cbl" }]);
2484
+ });
2485
+ it("code_dataflow_edges envelope is absent + abstain when no edges match", async () => {
2486
+ const wiki = freshWiki();
2487
+ const cobol = ` IDENTIFICATION DIVISION.
2488
+ PROGRAM-ID. ENVEDGE.
2489
+ PROCEDURE DIVISION.
2490
+ STOP RUN.`;
2491
+ wiki.rawAdd("ENVEDGE.cbl", { content: cobol });
2492
+ await handleTool(wiki, "code_parse", { path: "ENVEDGE.cbl" });
2493
+ const result = JSON.parse((await handleTool(wiki, "code_dataflow_edges", { path: "ENVEDGE.cbl" })));
2494
+ // No PROCEDURE DIVISION moves → no dataflow edges → absent.
2495
+ expect(result.evidence.confidence).toBe("absent");
2496
+ expect(result.evidence.abstain).toBe(true);
2497
+ expect(result.total).toBe(0);
2498
+ });
2499
+ it("code_dataflow_edges envelope is strong when edges exist", async () => {
2500
+ const wiki = freshWiki();
2501
+ const cobol = ` IDENTIFICATION DIVISION.
2502
+ PROGRAM-ID. ENVEDGE2.
2503
+ DATA DIVISION.
2504
+ WORKING-STORAGE SECTION.
2505
+ 01 WS-A PIC 9(4) VALUE 0.
2506
+ 01 WS-B PIC 9(4) VALUE 0.
2507
+ PROCEDURE DIVISION.
2508
+ MOVE WS-A TO WS-B.
2509
+ STOP RUN.`;
2510
+ wiki.rawAdd("ENVEDGE2.cbl", { content: cobol });
2511
+ await handleTool(wiki, "code_parse", { path: "ENVEDGE2.cbl" });
2512
+ const result = JSON.parse((await handleTool(wiki, "code_dataflow_edges", { path: "ENVEDGE2.cbl" })));
2513
+ expect(result.evidence.confidence).toBe("strong");
2514
+ expect(result.evidence.basis).toBe("deterministic");
2515
+ expect(result.evidence.provenance).toEqual([{ raw: "ENVEDGE2.cbl" }]);
2516
+ expect(result.total).toBeGreaterThan(0);
2517
+ });
2518
+ it("code_dataflow_edges transitive branch carries strong envelope when reachable", async () => {
2519
+ const wiki = freshWiki();
2520
+ const cobol = ` IDENTIFICATION DIVISION.
2521
+ PROGRAM-ID. ENVEDGE3.
2522
+ DATA DIVISION.
2523
+ WORKING-STORAGE SECTION.
2524
+ 01 WS-A PIC 9(4) VALUE 0.
2525
+ 01 WS-B PIC 9(4) VALUE 0.
2526
+ 01 WS-C PIC 9(4) VALUE 0.
2527
+ PROCEDURE DIVISION.
2528
+ MOVE WS-A TO WS-B.
2529
+ MOVE WS-B TO WS-C.
2530
+ STOP RUN.`;
2531
+ wiki.rawAdd("ENVEDGE3.cbl", { content: cobol });
2532
+ await handleTool(wiki, "code_parse", { path: "ENVEDGE3.cbl" });
2533
+ const result = JSON.parse((await handleTool(wiki, "code_dataflow_edges", {
2534
+ path: "ENVEDGE3.cbl",
2535
+ field: "WS-A",
2536
+ transitive: true,
2537
+ direction: "downstream",
2538
+ })));
2539
+ expect(result.transitive).toBe(true);
2540
+ expect(result.evidence.confidence).toBe("strong");
2541
+ expect(result.evidence.basis).toBe("deterministic");
2542
+ expect(result.evidence.rationale).toMatch(/Transitive downstream/);
2543
+ expect(result.total_edges).toBeGreaterThan(0);
2544
+ });
2545
+ it("code_dataflow_edges transitive branch is absent when start field has no edges", async () => {
2546
+ const wiki = freshWiki();
2547
+ const cobol = ` IDENTIFICATION DIVISION.
2548
+ PROGRAM-ID. ENVEDGE4.
2549
+ DATA DIVISION.
2550
+ WORKING-STORAGE SECTION.
2551
+ 01 WS-LONELY PIC 9(4) VALUE 0.
2552
+ PROCEDURE DIVISION.
2553
+ STOP RUN.`;
2554
+ wiki.rawAdd("ENVEDGE4.cbl", { content: cobol });
2555
+ await handleTool(wiki, "code_parse", { path: "ENVEDGE4.cbl" });
2556
+ const result = JSON.parse((await handleTool(wiki, "code_dataflow_edges", {
2557
+ path: "ENVEDGE4.cbl",
2558
+ field: "WS-LONELY",
2559
+ transitive: true,
2560
+ })));
2561
+ expect(result.transitive).toBe(true);
2562
+ expect(result.evidence.confidence).toBe("absent");
2563
+ expect(result.evidence.abstain).toBe(true);
2564
+ expect(result.total_edges).toBe(0);
2565
+ });
2566
+ it("code_procedure_flow envelope is absent when model has no sections or paragraphs", async () => {
2567
+ const wiki = freshWiki();
2568
+ // The COBOL parser synthesizes a default section+paragraph for inline-only
2569
+ // PROCEDURE DIVISION, so we can't trigger 0/0 via a real source. Write the
2570
+ // normalized artifact directly to exercise the absent branch — this is the
2571
+ // only path that produces sections+paragraphs === 0 for a parsed file.
2572
+ wiki.rawAdd("EMPTY.cbl", { content: " IDENTIFICATION DIVISION.\n PROGRAM-ID. EMPTY." });
2573
+ const emptyModel = {
2574
+ units: [{ name: "EMPTY", kind: "program" }],
2575
+ procedures: [],
2576
+ symbols: [],
2577
+ relations: [],
2578
+ diagnostics: [],
2579
+ };
2580
+ wiki.rawAddParsedArtifact("parsed/cobol/EMPTY.normalized.json", JSON.stringify(emptyModel));
2581
+ const result = JSON.parse((await handleTool(wiki, "code_procedure_flow", { path: "EMPTY.cbl" })));
2582
+ expect(result.evidence.confidence).toBe("absent");
2583
+ expect(result.evidence.abstain).toBe(true);
2584
+ expect(result.evidence.rationale).toMatch(/no sections or paragraphs/);
2585
+ });
2586
+ it("raw_read binary-non-image response carries envelope alongside metadata note", async () => {
2587
+ const wiki = freshWiki();
2588
+ const blob = Buffer.from([0x00, 0x01, 0x02, 0x03]);
2589
+ const rawPath = join(wiki.config.rawDir, "blob.dat");
2590
+ writeFileSync(rawPath, blob);
2591
+ writeFileSync(rawPath + ".meta.yaml", 'path: blob.dat\ndownloadedAt: "2026-05-01"\nsha256: dead\nsize: 4\nmimeType: application/octet-stream\n');
2592
+ const result = JSON.parse((await handleTool(wiki, "raw_read", { filename: "blob.dat" })));
2593
+ expect(result.binary).toBe(true);
2594
+ expect(result.note).toMatch(/Binary file/);
2595
+ expect(result.evidence.confidence).toBe("strong");
2596
+ expect(result.evidence.basis).toBe("deterministic");
2597
+ expect(result.evidence.provenance).toEqual([{ raw: "blob.dat" }]);
2598
+ });
2599
+ });
2418
2600
  describe("batch: wiki_admin action:rebuild is deduplicated", () => {
2419
2601
  beforeEach(cleanUp);
2420
2602
  afterEach(cleanUp);