Skip to content

Commit eabc2b3

Browse files
committed
test(structures): compare the api shape below the display depth, and list _-prefixed callables
1 parent 8f69631 commit eabc2b3

3 files changed

Lines changed: 60 additions & 10 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
*
3+
* @Project: @cldmv/slothlet
4+
* @Filename: /api_tests/api_test_special_numbers/nested.mjs
5+
* @Date: 2026-10-12T03:09:00-07:00 (1791799740)
6+
* @Author: Nate Corcoran <CLDMV>
7+
* @Email: <[email protected]>
8+
* -----
9+
* @Last modified by: Nate Corcoran <CLDMV> ([email protected])
10+
* @Last modified time: 2026-10-12T03:41:38-07:00 (1791801698)
11+
* -----
12+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13+
*
14+
*/
15+
16+
/**
17+
* @fileoverview Fixture (#585 review): a member deeper than the tool's display depth, and an underscore-prefixed function.
18+
* @module api_test_special_numbers.nested
19+
*/
20+
21+
export const tree = { a: { b: { c: { d: { e: { f: { g: { h: { i: { j: { leaf: 1 } } } } } } } } } } };
22+
23+
export function _hidden() {
24+
return "hidden";
25+
}

‎tests/vitests/suites/api-structures/inspect-api-shape-numbers.test.vitest.mjs‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @Email: <[email protected]>
88
* -----
99
* @Last modified by: Nate Corcoran <CLDMV> ([email protected])
10-
* @Last modified time: 2026-10-12T03:43:25-07:00 (1791801805)
10+
* @Last modified time: 2026-10-12T13:27:35-07:00 (1791836855)
1111
* -----
1212
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
1313
*
@@ -19,7 +19,9 @@
1919
* The shape is printed as JSON, which writes `NaN` and both infinities as `null` and `-0` as `0`, so two
2020
* apis differing only in those values would compare equal. Fixture `api_test_special_numbers` exports
2121
* each of them beside a real `0` and `null`. An array's `length` is part of its shape too: `arrays.mjs`
22-
* exports two arrays with the same enumerable elements, one with a trailing hole.
22+
* exports two arrays with the same enumerable elements, one with a trailing hole. `nested.mjs` exports a
23+
* member deeper than the display depth, which the shape still compares, and `_hidden()`, which the
24+
* callable paths list.
2325
* @module tests/vitests/suites/api-structures/inspect-api-shape-numbers
2426
*/
2527

@@ -33,17 +35,26 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.
3335
/**
3436
* Run the inspection tool on the fixture and read the api shape it prints.
3537
* @param {"--eager"|"--lazy"} modeFlag - Mode flag.
36-
* @returns {object} The api root's members.
38+
* @returns {{stdout: string, members: object}} The tool's output and the api root's members.
3739
*/
38-
function shapeOf(modeFlag) {
40+
function runTool(modeFlag) {
3941
const result = spawnSync("node", [path.join(ROOT, "tools", "dev", "inspect-api-structure.mjs"), "api_test_special_numbers", modeFlag], {
4042
cwd: ROOT,
4143
encoding: "utf8",
4244
env: { ...process.env, NODE_ENV: "development", NODE_OPTIONS: "--conditions=slothlet-dev" }
4345
});
4446
const line = result.stdout.split("\n").find((entry) => entry.startsWith("API Shape: "));
4547
expect(line, result.stderr).toBeDefined();
46-
return JSON.parse(line.slice("API Shape: ".length)).members;
48+
return { stdout: result.stdout, members: JSON.parse(line.slice("API Shape: ".length)).members };
49+
}
50+
51+
/**
52+
* Read the api shape the inspection tool prints for the fixture.
53+
* @param {"--eager"|"--lazy"} modeFlag - Mode flag.
54+
* @returns {object} The api root's members.
55+
*/
56+
function shapeOf(modeFlag) {
57+
return runTool(modeFlag).members;
4758
}
4859

4960
describe.each(["--eager", "--lazy"])("inspect-api-structure shape numbers (%s)", (modeFlag) => {
@@ -61,4 +72,14 @@ describe.each(["--eager", "--lazy"])("inspect-api-structure shape numbers (%s)",
6172
expect(arrays.holey.length).toBe(2);
6273
expect(arrays.short.length).toBe(1);
6374
});
75+
76+
it("compares the whole shape, below the display depth too", () => {
77+
let node = shapeOf(modeFlag).nested.members.tree;
78+
for (const key of ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "leaf"]) node = node.members[key];
79+
expect(node).toEqual({ type: "number", value: 1 });
80+
});
81+
82+
it("lists an underscore-prefixed function among the callable paths", () => {
83+
expect(runTool(modeFlag).stdout).toContain("api.nested._hidden()");
84+
});
6485
});

‎tools/dev/inspect-api-structure.mjs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @Email: <[email protected]>
88
* -----
99
* @Last modified by: Nate Corcoran <CLDMV> ([email protected])
10-
* @Last modified time: 2026-10-12T03:45:44-07:00 (1791801944)
10+
* @Last modified time: 2026-10-12T13:28:50-07:00 (1791836930)
1111
* -----
1212
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
1313
*
@@ -398,9 +398,11 @@ async function inspectApi(apiName, options = {}) {
398398
}
399399
}
400400

401-
// Mode-neutral shape of the whole api, for comparing eager and lazy composition (#583). Every lazy
402-
// node was loaded by findCallablePaths above.
403-
console.log(`\nAPI Shape: ${JSON.stringify(describeApiShape(api, 0, maxDepth))}`);
401+
// Mode-neutral shape of the whole api, for comparing eager and lazy composition (#583). It is not cut
402+
// at the display depth, which would make every subtree below it compare equal (#585 review), so
403+
// every lazy node is loaded first, at any depth.
404+
await findCallablePaths(api, "api", new WeakSet(), false, 0, Infinity);
405+
console.log(`\nAPI Shape: ${JSON.stringify(describeApiShape(api, 0, Infinity))}`);
404406

405407
// Shutdown the API instance to clean up resources
406408
if (typeof api.shutdown === "function") {
@@ -563,7 +565,9 @@ async function findCallablePaths(obj, basePath = "api", visited = new WeakSet(),
563565
// Search properties (works for both objects and functions since functions can have properties)
564566
if (typeof obj === "object" || typeof obj === "function") {
565567
for (const key of Object.keys(obj)) {
566-
if (key.startsWith("_") || key === "shutdown") continue;
568+
// A module's `_` and `__` members are api members like any other; the framework's own keys are
569+
// not on the node's surface (#585 review).
570+
if (key === "shutdown") continue;
567571
// A getter that throws is a member like any other; reading it must not end the walk.
568572
let value;
569573
try {

0 commit comments

Comments
 (0)