@context-engine-bridge/context-engine-mcp-bridge 0.0.75 → 0.0.76
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.
- package/package.json +1 -1
- package/.claude/settings.local.json +0 -11
- package/test/uploader.test.mjs +0 -158
package/package.json
CHANGED
package/test/uploader.test.mjs
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { execFileSync } from "node:child_process";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
computeLogicalRepoIdentity,
|
|
10
|
-
createBundle,
|
|
11
|
-
uploadBundle,
|
|
12
|
-
} from "../src/uploader.js";
|
|
13
|
-
|
|
14
|
-
test("computeLogicalRepoIdentity prefers normalized remote origin", async () => {
|
|
15
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "ctxce-bridge-git-"));
|
|
16
|
-
try {
|
|
17
|
-
execFileSync("git", ["init"], { cwd: tmpDir, stdio: "ignore" });
|
|
18
|
-
execFileSync("git", ["remote", "add", "origin", "git@github.com:Context-Engine-AI/Context-Engine.git"], {
|
|
19
|
-
cwd: tmpDir,
|
|
20
|
-
stdio: "ignore",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const identity = computeLogicalRepoIdentity(tmpDir);
|
|
24
|
-
assert.equal(identity.source, "remote_origin");
|
|
25
|
-
assert.match(identity.id, /^git:[0-9a-f]{16}$/);
|
|
26
|
-
} finally {
|
|
27
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("uploadBundle streams an exact multipart file payload", async () => {
|
|
32
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "ctxce-bridge-upload-"));
|
|
33
|
-
const workspacePath = path.join(tmpDir, "workspace");
|
|
34
|
-
fs.mkdirSync(workspacePath, { recursive: true });
|
|
35
|
-
|
|
36
|
-
const bundlePath = path.join(tmpDir, "bundle.tar.gz");
|
|
37
|
-
const bundleData = Buffer.from(Array.from({ length: 4096 }, (_, i) => i % 251));
|
|
38
|
-
fs.writeFileSync(bundlePath, bundleData);
|
|
39
|
-
|
|
40
|
-
let capturedBody = null;
|
|
41
|
-
let boundary = "";
|
|
42
|
-
const originalFetch = global.fetch;
|
|
43
|
-
global.fetch = async (_url, options) => {
|
|
44
|
-
boundary = String(options.headers["Content-Type"] || "").split("boundary=")[1] || "";
|
|
45
|
-
const chunks = [];
|
|
46
|
-
for await (const chunk of options.body) {
|
|
47
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
48
|
-
}
|
|
49
|
-
capturedBody = Buffer.concat(chunks);
|
|
50
|
-
return {
|
|
51
|
-
ok: true,
|
|
52
|
-
async json() {
|
|
53
|
-
return { success: true };
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const result = await uploadBundle(
|
|
60
|
-
bundlePath,
|
|
61
|
-
{
|
|
62
|
-
workspace_path: workspacePath,
|
|
63
|
-
collection_name: "demo-collection",
|
|
64
|
-
},
|
|
65
|
-
"http://example.invalid",
|
|
66
|
-
"session-token",
|
|
67
|
-
{ log: () => {} }
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
assert.equal(result.success, true);
|
|
71
|
-
assert.ok(capturedBody);
|
|
72
|
-
assert.ok(boundary);
|
|
73
|
-
|
|
74
|
-
const fileHeader = Buffer.from('Content-Disposition: form-data; name="bundle"; filename="bundle.tar.gz"\r\nContent-Type: application/gzip\r\n\r\n');
|
|
75
|
-
const headerIndex = capturedBody.indexOf(fileHeader);
|
|
76
|
-
assert.ok(headerIndex >= 0, "bundle header not found in multipart body");
|
|
77
|
-
|
|
78
|
-
const payloadStart = headerIndex + fileHeader.length;
|
|
79
|
-
const payloadEnd = capturedBody.indexOf(Buffer.from(`\r\n--${boundary}\r\n`), payloadStart);
|
|
80
|
-
assert.ok(payloadEnd > payloadStart, "bundle payload terminator not found");
|
|
81
|
-
|
|
82
|
-
const uploadedPayload = capturedBody.subarray(payloadStart, payloadEnd);
|
|
83
|
-
assert.deepEqual(uploadedPayload, bundleData);
|
|
84
|
-
} finally {
|
|
85
|
-
global.fetch = originalFetch;
|
|
86
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("createBundle writes metadata/, git_history.json, and git_state.json", async () => {
|
|
91
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "ctxce-bridge-bundle-"));
|
|
92
|
-
try {
|
|
93
|
-
execFileSync("git", ["init"], { cwd: tmpDir, stdio: "ignore" });
|
|
94
|
-
execFileSync("git", ["config", "user.email", "bridge@example.com"], { cwd: tmpDir, stdio: "ignore" });
|
|
95
|
-
execFileSync("git", ["config", "user.name", "Bridge Test"], { cwd: tmpDir, stdio: "ignore" });
|
|
96
|
-
execFileSync("git", ["remote", "add", "origin", "git@github.com:Context-Engine-AI/Bridge-Test.git"], {
|
|
97
|
-
cwd: tmpDir,
|
|
98
|
-
stdio: "ignore",
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
fs.writeFileSync(path.join(tmpDir, "index.js"), "export const value = 1;\n");
|
|
102
|
-
execFileSync("git", ["add", "index.js"], { cwd: tmpDir, stdio: "ignore" });
|
|
103
|
-
execFileSync("git", ["commit", "-m", "initial commit"], { cwd: tmpDir, stdio: "ignore" });
|
|
104
|
-
|
|
105
|
-
const bundle = await createBundle(tmpDir, { log: () => {} });
|
|
106
|
-
assert.ok(bundle);
|
|
107
|
-
|
|
108
|
-
const entries = execFileSync("tar", ["-tzf", bundle.bundlePath], { encoding: "utf8" })
|
|
109
|
-
.split("\n")
|
|
110
|
-
.filter(Boolean);
|
|
111
|
-
|
|
112
|
-
assert.ok(entries.some((entry) => entry.endsWith("/manifest.json")));
|
|
113
|
-
assert.ok(entries.some((entry) => entry.endsWith("/metadata/operations.json")));
|
|
114
|
-
assert.ok(entries.some((entry) => entry.endsWith("/metadata/hashes.json")));
|
|
115
|
-
assert.ok(entries.some((entry) => entry.endsWith("/metadata/git_history.json")));
|
|
116
|
-
assert.ok(entries.some((entry) => entry.endsWith("/metadata/git_state.json")));
|
|
117
|
-
assert.ok(!entries.some((entry) => entry.includes("/.metadata/")));
|
|
118
|
-
|
|
119
|
-
const historyEntry = entries.find((entry) => entry.endsWith("/metadata/git_history.json"));
|
|
120
|
-
const stateEntry = entries.find((entry) => entry.endsWith("/metadata/git_state.json"));
|
|
121
|
-
const historyJson = JSON.parse(
|
|
122
|
-
execFileSync("tar", ["-xOzf", bundle.bundlePath, historyEntry], { encoding: "utf8" })
|
|
123
|
-
);
|
|
124
|
-
const stateJson = JSON.parse(
|
|
125
|
-
execFileSync("tar", ["-xOzf", bundle.bundlePath, stateEntry], { encoding: "utf8" })
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
assert.equal(historyJson.repo_name, path.basename(tmpDir));
|
|
129
|
-
assert.equal(stateJson.logical_repo_source, "remote_origin");
|
|
130
|
-
assert.match(stateJson.logical_repo_id, /^git:[0-9a-f]{16}$/);
|
|
131
|
-
} finally {
|
|
132
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test("createBundle can build a history-only bundle for repos with no code files", async () => {
|
|
137
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "ctxce-bridge-history-only-"));
|
|
138
|
-
try {
|
|
139
|
-
execFileSync("git", ["init"], { cwd: tmpDir, stdio: "ignore" });
|
|
140
|
-
execFileSync("git", ["config", "user.email", "bridge@example.com"], { cwd: tmpDir, stdio: "ignore" });
|
|
141
|
-
execFileSync("git", ["config", "user.name", "Bridge Test"], { cwd: tmpDir, stdio: "ignore" });
|
|
142
|
-
fs.writeFileSync(path.join(tmpDir, "notes.txt"), "history only\n");
|
|
143
|
-
execFileSync("git", ["add", "notes.txt"], { cwd: tmpDir, stdio: "ignore" });
|
|
144
|
-
execFileSync("git", ["commit", "-m", "history only"], { cwd: tmpDir, stdio: "ignore" });
|
|
145
|
-
|
|
146
|
-
const bundle = await createBundle(tmpDir, { log: () => {}, allowEmpty: true });
|
|
147
|
-
assert.ok(bundle);
|
|
148
|
-
assert.equal(bundle.manifest.total_files, 0);
|
|
149
|
-
|
|
150
|
-
const entries = execFileSync("tar", ["-tzf", bundle.bundlePath], { encoding: "utf8" })
|
|
151
|
-
.split("\n")
|
|
152
|
-
.filter(Boolean);
|
|
153
|
-
assert.ok(entries.some((entry) => entry.endsWith("/metadata/git_history.json")));
|
|
154
|
-
assert.ok(entries.some((entry) => entry.endsWith("/metadata/operations.json")));
|
|
155
|
-
} finally {
|
|
156
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
157
|
-
}
|
|
158
|
-
});
|