Skip to content

Commit 3a8dacb

Browse files
committed
fix(validation): fix import paths and module resolution after reorganization
- Fix representativeness test fixtures imports (use ./fixtures/ relative path) - Update test-graph-expander.ts to use correct relative paths for Graph/Neighbor - Fix common/baselines and common/representativeness-helpers import paths - Add vite-tsconfig-paths plugin for better TypeScript path resolution - Configure resolve.extensions in vitest to include .ts files - Change tsconfig moduleResolution from "bundler" to "node" All 32 test files now passing with 67 tests total.
1 parent 0d96820 commit 3a8dacb

File tree

38 files changed

+340
-124
lines changed

38 files changed

+340
-124
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"typescript-eslint": "^8.53.0",
9090
"vite": "7.3.1",
9191
"vite-plugin-dts": "^4.5.4",
92+
"vite-tsconfig-paths": "^6.0.4",
9293
"vitest": "4.0.17"
9394
},
9495
"dependencies": {

pnpm-lock.yaml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/**
2+
* Shared test infrastructure for representativeness tests
3+
*/
4+
5+
import { Graph } from "../../../../../../../../../../../algorithms/graph/graph";
6+
import type { Neighbor } from "../../../../../../../../../../../interfaces/graph-expander";
7+
8+
export interface TestNode {
9+
id: string;
10+
type: string;
11+
[key: string]: unknown;
12+
}
13+
14+
export interface TestEdge {
15+
id: string;
16+
source: string;
17+
target: string;
18+
type: string;
19+
[key: string]: unknown;
20+
}
21+
22+
/**
23+
* Adapter to use Graph class with expansion algorithms
24+
*/
25+
export class GraphExpanderAdapter {
26+
private adjacency = new Map<string, Neighbor[]>();
27+
private degrees = new Map<string, number>();
28+
private nodes = new Map<string, TestNode>();
29+
30+
constructor(
31+
private readonly graph: Graph<TestNode, TestEdge>,
32+
directed = false
33+
) {
34+
for (const node of graph.getAllNodes()) {
35+
this.nodes.set(node.id, node);
36+
this.adjacency.set(node.id, []);
37+
}
38+
39+
for (const edge of graph.getAllEdges()) {
40+
const neighbors = this.adjacency.get(edge.source) ?? [];
41+
neighbors.push({ targetId: edge.target, relationshipType: edge.type ?? "edge" });
42+
this.adjacency.set(edge.source, neighbors);
43+
44+
if (!directed) {
45+
const reverseNeighbors = this.adjacency.get(edge.target) ?? [];
46+
reverseNeighbors.push({ targetId: edge.source, relationshipType: edge.type ?? "edge" });
47+
this.adjacency.set(edge.target, reverseNeighbors);
48+
}
49+
}
50+
51+
for (const [nodeId, neighbors] of this.adjacency) {
52+
this.degrees.set(nodeId, neighbors.length);
53+
}
54+
}
55+
56+
async getNeighbors(nodeId: string): Promise<Neighbor[]> {
57+
return this.adjacency.get(nodeId) ?? [];
58+
}
59+
60+
getDegree(nodeId: string): number {
61+
return this.degrees.get(nodeId) ?? 0;
62+
}
63+
64+
async getNode(nodeId: string): Promise<TestNode | null> {
65+
return this.nodes.get(nodeId) ?? null;
66+
}
67+
68+
addEdge(): void {
69+
// No-op
70+
}
71+
72+
calculatePriority(nodeId: string, options: { nodeWeight?: number; epsilon?: number } = {}): number {
73+
const { nodeWeight = 1, epsilon = 1e-10 } = options;
74+
const degree = this.getDegree(nodeId);
75+
return degree / (nodeWeight + epsilon);
76+
}
77+
78+
getAllDegrees(): Map<string, number> {
79+
return this.degrees;
80+
}
81+
}
82+
83+
/**
84+
* Create a test graph from edge list
85+
*/
86+
export const createGraph = (edges: Array<[string, string]>): Graph<TestNode, TestEdge> => {
87+
const graph = new Graph<TestNode, TestEdge>(false);
88+
89+
const nodeIds = new Set<string>();
90+
for (const [source, target] of edges) {
91+
nodeIds.add(source);
92+
nodeIds.add(target);
93+
}
94+
95+
for (const id of nodeIds) {
96+
graph.addNode({ id, type: "test" });
97+
}
98+
99+
let edgeCounter = 0;
100+
for (const [source, target] of edges) {
101+
graph.addEdge({ id: `e${edgeCounter++}`, source, target, type: "edge" });
102+
graph.addEdge({ id: `e${edgeCounter++}`, source: target, target: source, type: "edge" });
103+
}
104+
105+
return graph;
106+
};
107+
108+
/**
109+
* Create a chain graph (linear path)
110+
*/
111+
export const createChainGraph = (length: number): Graph<TestNode, TestEdge> => {
112+
const edges: Array<[string, string]> = [];
113+
for (let index = 0; index < length - 1; index++) {
114+
edges.push([`N${index}`, `N${index + 1}`]);
115+
}
116+
return createGraph(edges);
117+
};
118+
119+
/**
120+
* Create a grid graph (rows x cols)
121+
*/
122+
export const createGridGraph = (rows: number, cols: number): Graph<TestNode, TestEdge> => {
123+
const edges: Array<[string, string]> = [];
124+
125+
for (let r = 0; r < rows; r++) {
126+
for (let c = 0; c < cols; c++) {
127+
const node = `${r}_${c}`;
128+
if (c < cols - 1) {
129+
edges.push([node, `${r}_${c + 1}`]);
130+
}
131+
if (r < rows - 1) {
132+
edges.push([node, `${r + 1}_${c}`]);
133+
}
134+
}
135+
}
136+
137+
return createGraph(edges);
138+
};
139+
140+
/**
141+
* Create a hub graph with central hub nodes and leaf nodes
142+
*/
143+
export const createHubGraph = (numberHubs: number, leavesPerHub: number): Graph<TestNode, TestEdge> => {
144+
const edges: Array<[string, string]> = [];
145+
146+
// Connect hubs
147+
for (let index = 0; index < numberHubs; index++) {
148+
for (let index_ = index + 1; index_ < numberHubs; index_++) {
149+
edges.push([`H${index}`, `H${index_}`]);
150+
}
151+
}
152+
153+
// Connect leaves
154+
for (let h = 0; h < numberHubs; h++) {
155+
for (let l = 0; l < leavesPerHub; l++) {
156+
edges.push([`H${h}`, `L${h}_${l}`]);
157+
}
158+
}
159+
160+
return createGraph(edges);
161+
};

src/experiments/evaluation/__tests__/validation/comparative/comparative-summary.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { describe, expect, it } from "vitest";
1111

1212
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
13-
import { StandardBfsExpansion } from "../../../../baselines/standard-bfs";
13+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
1414
import { createHubGraphExpander } from "../common/graph-generators";
1515
import { jaccardSimilarity } from "../common/statistical-functions";
1616

src/experiments/evaluation/__tests__/validation/comparative/literature-review-metrics.integration.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
import { describe, expect, it } from "vitest";
1414

15-
import { BenchmarkGraphExpander } from "../../common/benchmark-graph-expander";
16-
import { loadBenchmarkByIdFromUrl } from "../../../../fixtures/benchmark-datasets";
15+
import { BenchmarkGraphExpander } from "../common/benchmark-graph-expander";
16+
import { loadBenchmarkByIdFromUrl } from "../../../fixtures/benchmark-datasets";
1717
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
18-
import { StandardBfsExpansion } from "../../../baselines/standard-bfs";
19-
import { pathDiversity } from "../../common/statistical-functions";
18+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
19+
import { pathDiversity } from "../common/statistical-functions";
2020

2121
describe("Systematic Literature Review Metrics", () => {
2222
/**

src/experiments/evaluation/__tests__/validation/comparative/method-ranking.integration.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import { describe, expect, it } from "vitest";
99

1010
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
11-
import { BenchmarkGraphExpander } from "../../common/benchmark-graph-expander";
11+
import { BenchmarkGraphExpander } from "../common/benchmark-graph-expander";
1212
import { loadBenchmarkByIdFromUrl } from "../../../fixtures/benchmark-datasets";
13-
import { HighDegreeFirstExpansion } from "../../common/baselines/high-degree-first";
14-
import { LowDegreeFirstExpansion } from "../../common/baselines/low-degree-first";
15-
import { FrontierBalancedExpansion } from "../../../../baselines/frontier-balanced";
16-
import { RandomPriorityExpansion } from "../../../../baselines/random-priority";
17-
import { StandardBfsExpansion } from "../../../../baselines/standard-bfs";
18-
import { pathDiversity } from "../../common/statistical-functions";
13+
import { HighDegreeFirstExpansion } from "../common/baselines/high-degree-first";
14+
import { LowDegreeFirstExpansion } from "../common/baselines/low-degree-first";
15+
import { FrontierBalancedExpansion } from "../../../../../experiments/baselines/frontier-balanced"
16+
import { RandomPriorityExpansion } from "../../../../../experiments/baselines/random-priority"
17+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
18+
import { pathDiversity } from "../common/statistical-functions";
1919

2020
describe("Thesis Validation: Additional Baselines", () => {
2121
it("should compare thesis method vs high-degree-first baseline", async () => {

src/experiments/evaluation/__tests__/validation/comparative/multi-method-comparison.integration.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import { describe, expect, it } from "vitest";
1010

11-
import { DegreePrioritisedExpansion } from "../../../../algorithms/traversal/degree-prioritised-expansion";
11+
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
1212

1313
import { BenchmarkGraphExpander } from "../common/benchmark-graph-expander";
1414
import { loadBenchmarkByIdFromUrl } from "../../../fixtures/benchmark-datasets";
15-
import { FrontierBalancedExpansion } from "../../../../baselines/frontier-balanced";
16-
import { RandomPriorityExpansion } from "../../../../baselines/random-priority";
17-
import { StandardBfsExpansion } from "../../../../baselines/standard-bfs";
15+
import { FrontierBalancedExpansion } from "../../../../../experiments/baselines/frontier-balanced"
16+
import { RandomPriorityExpansion } from "../../../../../experiments/baselines/random-priority"
17+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
1818
import { cohensD, confidenceInterval, mannWhitneyUTest } from "../common/statistical-functions";
1919

2020
describe("Thesis Validation: Statistical Tests", () => {

src/experiments/evaluation/__tests__/validation/comparative/perturbation-consistency.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
loadBenchmarkFromContent,
1616
} from "../../../fixtures/benchmark-datasets";
1717
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
18-
import { StandardBfsExpansion } from "../../../../baselines/standard-bfs";
18+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
1919
import { pathDiversity } from "../common/statistical-functions";
2020

2121
describe("Thesis Validation: Perturbed Graph Robustness", () => {

src/experiments/evaluation/__tests__/validation/comparative/validation-summary.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
loadBenchmarkFromContent,
1616
} from "../../../fixtures/benchmark-datasets";
1717
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
18-
import { StandardBfsExpansion } from "../../../../baselines/standard-bfs";
18+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
1919
import { jaccardSimilarity, pathDiversity } from "../common/statistical-functions";
2020

2121
// ============================================================================

src/experiments/evaluation/__tests__/validation/comparative/variability-injection.integration.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { describe, expect, it } from "vitest";
2-
import { BenchmarkGraphExpander } from "../../common/benchmark-graph-expander";
2+
import { BenchmarkGraphExpander } from "../common/benchmark-graph-expander";
33
import { loadBenchmarkByIdFromUrl } from "../../../fixtures/benchmark-datasets";
4-
import { DegreePrioritisedExpansion } from "../../../../baselines/degree-prioritised-expansion";
5-
import { StandardBfsExpansion } from "../../../../baselines/standard-bfs-expansion";
6-
import { RandomPriorityExpansion } from "../../../../baselines/random-priority-expansion";
7-
import { mannWhitneyUTest, cohensD, confidenceInterval, pathDiversity } from "../../common/statistical-functions";
4+
import { DegreePrioritisedExpansion } from "../../../../../algorithms/traversal/degree-prioritised-expansion";
5+
import { StandardBfsExpansion } from "../../../../../experiments/baselines/standard-bfs"
6+
import { RandomPriorityExpansion } from "../../../../../experiments/baselines/random-priority"
7+
import { mannWhitneyUTest, cohensD, confidenceInterval, pathDiversity } from "../common/statistical-functions";
88

99
describe("Thesis Validation: Variability Injection", () => {
1010
describe("Multiple Seed Pair Analysis", () => {

0 commit comments

Comments
 (0)