kodingo-cli 1.3.1 → 1.3.2
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.
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Real tests for C#/.NET support in tree-sitter-parser.ts / ast-parser.ts —
|
|
4
|
+
* build brief "Add real C#/.NET support to the CLI's parser" (2026-09-20).
|
|
5
|
+
*
|
|
6
|
+
* The real bar per the brief: not just "C# symbols get extracted", but
|
|
7
|
+
* genuine, stable deduplication — the same, unchanged function produces a
|
|
8
|
+
* byte-for-byte identical fingerprint across repeated runs, and a genuinely
|
|
9
|
+
* changed function's fingerprint correctly changes.
|
|
10
|
+
*
|
|
11
|
+
* Uses Node's built-in test runner (node:test) — this repo has no existing
|
|
12
|
+
* test framework to inherit (confirmed: package.json's own "test" script
|
|
13
|
+
* was a stub), and node:test needs zero new dependencies. Compiled and run
|
|
14
|
+
* via `npm test` (tsc then `node --test dist/__tests__`).
|
|
15
|
+
*/
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const node_test_1 = require("node:test");
|
|
21
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
22
|
+
const tree_sitter_parser_1 = require("../utils/tree-sitter-parser");
|
|
23
|
+
const ast_parser_1 = require("../utils/ast-parser");
|
|
24
|
+
const REAL_CSHARP_SOURCE = `
|
|
25
|
+
using System;
|
|
26
|
+
using System.Threading.Tasks;
|
|
27
|
+
|
|
28
|
+
namespace Acme.Orders
|
|
29
|
+
{
|
|
30
|
+
public class OrderService : IOrderService
|
|
31
|
+
{
|
|
32
|
+
private readonly IRepository _repo;
|
|
33
|
+
|
|
34
|
+
public OrderService(IRepository repo)
|
|
35
|
+
{
|
|
36
|
+
_repo = repo;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async Task<Order> GetOrderAsync(int id)
|
|
40
|
+
{
|
|
41
|
+
var order = await _repo.FindAsync(id);
|
|
42
|
+
LogAccess(id);
|
|
43
|
+
return order;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private void LogAccess(int id)
|
|
47
|
+
{
|
|
48
|
+
Console.WriteLine($"Accessed order {id}");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public static int Add(int a, int b)
|
|
52
|
+
{
|
|
53
|
+
if (a > 0)
|
|
54
|
+
{
|
|
55
|
+
return a + b;
|
|
56
|
+
}
|
|
57
|
+
return b;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public interface IOrderService
|
|
62
|
+
{
|
|
63
|
+
Task<Order> GetOrderAsync(int id);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public struct Point
|
|
67
|
+
{
|
|
68
|
+
public int Sum(int x, int y) => x + y;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public record OrderDto(int Id, string Name)
|
|
72
|
+
{
|
|
73
|
+
public string Describe() => $"{Id}: {Name}";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public class Order { }
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
// A real, structural change to GetOrderAsync — a distinct code path added,
|
|
80
|
+
// not a cosmetic rename/whitespace/comment tweak (those are what
|
|
81
|
+
// computeFingerprint is specifically designed to SURVIVE).
|
|
82
|
+
const CHANGED_CSHARP_SOURCE = REAL_CSHARP_SOURCE.replace(`public async Task<Order> GetOrderAsync(int id)
|
|
83
|
+
{
|
|
84
|
+
var order = await _repo.FindAsync(id);
|
|
85
|
+
LogAccess(id);
|
|
86
|
+
return order;
|
|
87
|
+
}`, `public async Task<Order> GetOrderAsync(int id)
|
|
88
|
+
{
|
|
89
|
+
var order = await _repo.FindAsync(id);
|
|
90
|
+
LogAccess(id);
|
|
91
|
+
if (order == null) throw new InvalidOperationException("not found");
|
|
92
|
+
return order;
|
|
93
|
+
}`);
|
|
94
|
+
(0, node_test_1.describe)("parseWithTreeSitter — real C# extraction", () => {
|
|
95
|
+
(0, node_test_1.it)("extracts every real method, constructor, and local function with class-qualified names", async () => {
|
|
96
|
+
const symbols = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
97
|
+
const names = symbols.map(s => s.name).sort();
|
|
98
|
+
strict_1.default.deepEqual(names, [
|
|
99
|
+
"IOrderService.GetOrderAsync",
|
|
100
|
+
"OrderDto.Describe",
|
|
101
|
+
"OrderService.Add",
|
|
102
|
+
"OrderService.GetOrderAsync",
|
|
103
|
+
"OrderService.LogAccess",
|
|
104
|
+
"OrderService.OrderService",
|
|
105
|
+
"Point.Sum",
|
|
106
|
+
].sort());
|
|
107
|
+
});
|
|
108
|
+
(0, node_test_1.it)("real, correct method vs constructor typing", async () => {
|
|
109
|
+
const symbols = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
110
|
+
const ctor = symbols.find(s => s.name === "OrderService.OrderService");
|
|
111
|
+
const method = symbols.find(s => s.name === "OrderService.GetOrderAsync");
|
|
112
|
+
strict_1.default.equal(ctor?.type, "method");
|
|
113
|
+
strict_1.default.equal(method?.type, "method");
|
|
114
|
+
});
|
|
115
|
+
(0, node_test_1.it)("real call extraction trims member-access callees to their trailing identifier", async () => {
|
|
116
|
+
const symbols = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
117
|
+
const method = symbols.find(s => s.name === "OrderService.GetOrderAsync");
|
|
118
|
+
strict_1.default.ok(method);
|
|
119
|
+
strict_1.default.ok(method.calls.includes("FindAsync"), `expected FindAsync in ${JSON.stringify(method.calls)}`);
|
|
120
|
+
strict_1.default.ok(method.calls.includes("LogAccess"), `expected LogAccess in ${JSON.stringify(method.calls)}`);
|
|
121
|
+
});
|
|
122
|
+
(0, node_test_1.it)("real using-directive extraction", async () => {
|
|
123
|
+
const symbols = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
124
|
+
strict_1.default.ok(symbols[0].imports.some(i => i.source.includes("using System;")));
|
|
125
|
+
strict_1.default.ok(symbols[0].imports.some(i => i.source.includes("using System.Threading.Tasks;")));
|
|
126
|
+
});
|
|
127
|
+
(0, node_test_1.it)("returns [] for an unrecognized extension rather than throwing", async () => {
|
|
128
|
+
const symbols = await (0, tree_sitter_parser_1.parseWithTreeSitter)("readme.md", "# not code");
|
|
129
|
+
strict_1.default.deepEqual(symbols, []);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
(0, node_test_1.describe)("real deduplication — the actual bar this brief is judged against", () => {
|
|
133
|
+
(0, node_test_1.it)("the SAME, unchanged C# function produces a byte-for-byte identical fingerprint across repeated runs", async () => {
|
|
134
|
+
const run1 = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
135
|
+
const run2 = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
136
|
+
const run3 = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
137
|
+
const fp1 = run1.find(s => s.name === "OrderService.GetOrderAsync")?.fingerprint;
|
|
138
|
+
const fp2 = run2.find(s => s.name === "OrderService.GetOrderAsync")?.fingerprint;
|
|
139
|
+
const fp3 = run3.find(s => s.name === "OrderService.GetOrderAsync")?.fingerprint;
|
|
140
|
+
strict_1.default.ok(fp1);
|
|
141
|
+
strict_1.default.equal(fp1, fp2);
|
|
142
|
+
strict_1.default.equal(fp2, fp3);
|
|
143
|
+
// Every single real symbol in the file, not just one — genuine, stable
|
|
144
|
+
// dedup across the whole file, not a cherry-picked case.
|
|
145
|
+
for (let i = 0; i < run1.length; i++) {
|
|
146
|
+
strict_1.default.equal(run1[i].fingerprint, run2[i].fingerprint, `symbol ${run1[i].name} fingerprint drifted across runs`);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
(0, node_test_1.it)("via the real, full parseFile dispatch (the actual path scan-repo.ts calls) — same stability", async () => {
|
|
150
|
+
const run1 = await (0, ast_parser_1.parseFile)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
151
|
+
const run2 = await (0, ast_parser_1.parseFile)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
152
|
+
strict_1.default.ok(run1.length > 0);
|
|
153
|
+
strict_1.default.deepEqual(run1.map(s => s.fingerprint), run2.map(s => s.fingerprint));
|
|
154
|
+
});
|
|
155
|
+
(0, node_test_1.it)("cosmetic-only changes (comments, whitespace) do NOT change the fingerprint — by design", async () => {
|
|
156
|
+
const cosmetic = REAL_CSHARP_SOURCE.replace(`public static int Add(int a, int b)`, `// adds two numbers\n public static int Add(int a, int b)`);
|
|
157
|
+
const before = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
158
|
+
const after = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", cosmetic);
|
|
159
|
+
const fpBefore = before.find(s => s.name === "OrderService.Add")?.fingerprint;
|
|
160
|
+
const fpAfter = after.find(s => s.name === "OrderService.Add")?.fingerprint;
|
|
161
|
+
strict_1.default.equal(fpBefore, fpAfter);
|
|
162
|
+
});
|
|
163
|
+
(0, node_test_1.it)("a genuinely CHANGED function's fingerprint correctly changes — an edit is not invisible", async () => {
|
|
164
|
+
const before = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", REAL_CSHARP_SOURCE);
|
|
165
|
+
const after = await (0, tree_sitter_parser_1.parseWithTreeSitter)("OrderService.cs", CHANGED_CSHARP_SOURCE);
|
|
166
|
+
const fpBefore = before.find(s => s.name === "OrderService.GetOrderAsync")?.fingerprint;
|
|
167
|
+
const fpAfter = after.find(s => s.name === "OrderService.GetOrderAsync")?.fingerprint;
|
|
168
|
+
strict_1.default.ok(fpBefore);
|
|
169
|
+
strict_1.default.ok(fpAfter);
|
|
170
|
+
strict_1.default.notEqual(fpBefore, fpAfter);
|
|
171
|
+
// Every OTHER real symbol in the file is untouched by the edit and must
|
|
172
|
+
// keep its own stable fingerprint — proving the change is properly
|
|
173
|
+
// scoped to the actual edited function, not a global reshuffle.
|
|
174
|
+
for (const name of ["OrderService.Add", "OrderService.LogAccess", "OrderService.OrderService", "Point.Sum"]) {
|
|
175
|
+
const b = before.find(s => s.name === name)?.fingerprint;
|
|
176
|
+
const a = after.find(s => s.name === name)?.fingerprint;
|
|
177
|
+
strict_1.default.equal(b, a, `unrelated symbol ${name} should not have changed`);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
(0, node_test_1.describe)("computeFingerprint — sanity on real C# body text", () => {
|
|
182
|
+
(0, node_test_1.it)("normalizes C# string interpolation/comments deterministically", () => {
|
|
183
|
+
const a = (0, ast_parser_1.computeFingerprint)(`Console.WriteLine($"Accessed order {id}"); // log it`);
|
|
184
|
+
const b = (0, ast_parser_1.computeFingerprint)(`Console.WriteLine($"Accessed order {id}");`);
|
|
185
|
+
strict_1.default.equal(a, b);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -61,7 +61,7 @@ const API_BASE = "https://kodingo-api.onrender.com";
|
|
|
61
61
|
const SUPPORTED_EXTENSIONS = [
|
|
62
62
|
".ts", ".tsx", ".js", ".jsx",
|
|
63
63
|
".py", ".go", ".rs", ".php",
|
|
64
|
-
".java", ".kt", ".rb", ".c", ".cpp",
|
|
64
|
+
".java", ".kt", ".rb", ".c", ".cpp", ".cs",
|
|
65
65
|
];
|
|
66
66
|
const IGNORED_DIRS = [
|
|
67
67
|
"node_modules", ".git", ".kortex", "dist", "build",
|
package/dist/utils/ast-parser.js
CHANGED
|
@@ -417,7 +417,7 @@ const KOTLIN_PATTERNS = [
|
|
|
417
417
|
/^(?:fun|override\s+fun|suspend\s+fun|private\s+fun|public\s+fun)\s+(\w+)/,
|
|
418
418
|
/^(?:class|data class|object|interface)\s+(\w+)/,
|
|
419
419
|
];
|
|
420
|
-
const TREE_SITTER_EXTENSIONS = new Set([".py", ".go", ".rs", ".java", ".kt", ".rb", ".php", ".c", ".cpp"]);
|
|
420
|
+
const TREE_SITTER_EXTENSIONS = new Set([".py", ".go", ".rs", ".java", ".kt", ".rb", ".php", ".c", ".cpp", ".cs"]);
|
|
421
421
|
async function parseFile(filePath, source) {
|
|
422
422
|
const ext = path.extname(filePath).toLowerCase();
|
|
423
423
|
switch (ext) {
|
|
@@ -64,7 +64,7 @@ const ast_parser_1 = require("./ast-parser");
|
|
|
64
64
|
const SUPPORTED_EXTENSIONS = [
|
|
65
65
|
".ts", ".tsx", ".js", ".jsx",
|
|
66
66
|
".py", ".go", ".rs", ".php",
|
|
67
|
-
".java", ".kt", ".rb", ".c", ".cpp",
|
|
67
|
+
".java", ".kt", ".rb", ".c", ".cpp", ".cs",
|
|
68
68
|
];
|
|
69
69
|
const TS_JS_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx"]);
|
|
70
70
|
const IGNORED_DIRS = [
|
|
@@ -104,6 +104,31 @@ const LANGUAGE_CONFIGS = {
|
|
|
104
104
|
nameFieldCandidates: [], // handled via declarator fallback
|
|
105
105
|
importTypes: ["preproc_include"],
|
|
106
106
|
},
|
|
107
|
+
// C# — build brief "Add real C#/.NET support to the CLI's parser"
|
|
108
|
+
// (2026-09-20). Real node types confirmed directly against the bundled
|
|
109
|
+
// tree-sitter-c_sharp.wasm grammar (tree-sitter-wasms package, already a
|
|
110
|
+
// real dependency here — no new native package needed, see this brief's
|
|
111
|
+
// own final report for why that matters). method_declaration,
|
|
112
|
+
// constructor_declaration, and local_function_statement all carry a real
|
|
113
|
+
// `name` field; invocation_expression carries a real `function` field
|
|
114
|
+
// whose text (e.g. "_repo.FindAsync", "Console.WriteLine") is trimmed to
|
|
115
|
+
// its trailing identifier by the same extractTrailingIdentifier() already
|
|
116
|
+
// proven for PHP's "$this->service->method" shape — no C#-specific call
|
|
117
|
+
// handling needed. Deliberately excludes operator_declaration,
|
|
118
|
+
// destructor_declaration, and property accessors — real, distinct node
|
|
119
|
+
// shapes with no `name` field (or none at all) that no other language
|
|
120
|
+
// here gets special-cased treatment for either; kept proportionate to the
|
|
121
|
+
// existing five languages' own level of coverage rather than gold-plating
|
|
122
|
+
// C# beyond them.
|
|
123
|
+
csharp: {
|
|
124
|
+
wasmFile: "tree-sitter-c_sharp.wasm",
|
|
125
|
+
functionTypes: ["method_declaration", "constructor_declaration", "local_function_statement"],
|
|
126
|
+
classTypes: ["class_declaration", "interface_declaration", "struct_declaration", "record_declaration"],
|
|
127
|
+
callTypes: ["invocation_expression"],
|
|
128
|
+
calleeFieldCandidates: ["function"],
|
|
129
|
+
nameFieldCandidates: ["name"],
|
|
130
|
+
importTypes: ["using_directive"],
|
|
131
|
+
},
|
|
107
132
|
};
|
|
108
133
|
const EXT_TO_LANGUAGE = {
|
|
109
134
|
".py": "python",
|
|
@@ -115,6 +140,7 @@ const EXT_TO_LANGUAGE = {
|
|
|
115
140
|
".php": "php",
|
|
116
141
|
".c": "c",
|
|
117
142
|
".cpp": "cpp",
|
|
143
|
+
".cs": "csharp",
|
|
118
144
|
};
|
|
119
145
|
let initialised = false;
|
|
120
146
|
const languageCache = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kodingo-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Kodingo CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "tsc -p tsconfig.json",
|
|
17
17
|
"dev": "tsc -p tsconfig.json --watch",
|
|
18
18
|
"start": "node dist/cli.js",
|
|
19
|
-
"test": "
|
|
19
|
+
"test": "npm run build && node --test dist/__tests__/*.js",
|
|
20
20
|
"prepare": "npm run build"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|