@bash0816/claude-code 2.1.276 → 2.1.280
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/README.md +4 -1
- package/config/claude-native-audited-versions.json +148 -1
- package/config/claude-termux-release-manifest.json +3 -3
- package/lib/bunfs-esm-loader.mjs +156 -0
- package/lib/bunfs-esm-loader.test.js +885 -0
- package/lib/bunfs-extract.js +10 -1
- package/lib/bunfs-extract.test.js +36 -3
- package/lib/hooks-standalone-pattern.js +7 -0
- package/lib/hooks-standalone-pattern.test.js +115 -0
- package/lib/termux-run-claude-native.sh +24 -0
- package/lib/termux-run-claude-native.test.js +82 -0
- package/package.json +1 -1
package/lib/bunfs-extract.js
CHANGED
|
@@ -9,6 +9,13 @@ const MODULE_TABLE_ENTRY_SIZE = 52;
|
|
|
9
9
|
const SCAN_CHUNK_SIZE = 1024 * 1024;
|
|
10
10
|
const NAPI_LOADER = 10;
|
|
11
11
|
|
|
12
|
+
class ModuleGraphNotFoundError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'ModuleGraphNotFoundError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
function readRange(fd, offset, length) {
|
|
13
20
|
const buf = Buffer.alloc(length);
|
|
14
21
|
const bytesRead = readSync(fd, buf, 0, length, offset);
|
|
@@ -26,7 +33,7 @@ function findTrailerOffset(fd, fileSize) {
|
|
|
26
33
|
const idx = buf.lastIndexOf(TRAILER);
|
|
27
34
|
if (idx >= 0) return start + idx;
|
|
28
35
|
}
|
|
29
|
-
throw new
|
|
36
|
+
throw new ModuleGraphNotFoundError('bunfs-extract: StandaloneModuleGraph trailer not found');
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
function isSafeUint(value) {
|
|
@@ -197,6 +204,8 @@ function readEntryContentPrefix(fd, entryModule, maxLength = 256) {
|
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
module.exports = {
|
|
207
|
+
TRAILER,
|
|
208
|
+
ModuleGraphNotFoundError,
|
|
200
209
|
discoverModuleGraph,
|
|
201
210
|
extractToProcessOwnedDir,
|
|
202
211
|
cleanupStaleOwnedDirs,
|
|
@@ -8,14 +8,14 @@ const path = require('node:path');
|
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
discoverModuleGraph,
|
|
11
|
+
ModuleGraphNotFoundError,
|
|
12
|
+
TRAILER,
|
|
11
13
|
extractToProcessOwnedDir,
|
|
12
14
|
cleanupStaleOwnedDirs,
|
|
13
15
|
prepareProcessOwnedDir,
|
|
14
16
|
readEntryContentPrefix,
|
|
15
17
|
} = require('./bunfs-extract.js');
|
|
16
18
|
|
|
17
|
-
const TRAILER = '\n---- Bun! ----\n';
|
|
18
|
-
|
|
19
19
|
// StandaloneModuleGraphの最小合成バイナリを構築する。
|
|
20
20
|
// レイアウト: [preamble padding][module contents][module table][Offsets(32byte)][trailer]
|
|
21
21
|
function buildSyntheticBinary({ modules, entryPointId, corruptTrailer = false, preamblePadding = 64 }) {
|
|
@@ -58,7 +58,7 @@ function buildSyntheticBinary({ modules, entryPointId, corruptTrailer = false, p
|
|
|
58
58
|
offsetsBuf.writeUInt32LE(modulesLength, 12);
|
|
59
59
|
offsetsBuf.writeUInt32LE(entryPointId, 16);
|
|
60
60
|
|
|
61
|
-
const trailerBuf = Buffer.from(
|
|
61
|
+
const trailerBuf = corruptTrailer ? Buffer.from('\n---- NOT BUN ----\n', 'utf8') : TRAILER;
|
|
62
62
|
|
|
63
63
|
return Buffer.concat([
|
|
64
64
|
Buffer.alloc(preamblePadding),
|
|
@@ -114,6 +114,39 @@ test('discoverModuleGraph rejects a binary with a corrupted trailer', () => {
|
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
test('discoverModuleGraph throws ModuleGraphNotFoundError when the trailer is absent', () => {
|
|
118
|
+
const file = writeTempBinary(Buffer.from('not a bun standalone module graph'));
|
|
119
|
+
try {
|
|
120
|
+
assert.throws(() => discoverModuleGraph(file), (error) => {
|
|
121
|
+
assert.ok(error instanceof ModuleGraphNotFoundError);
|
|
122
|
+
assert.match(error.message, /trailer not found/);
|
|
123
|
+
return true;
|
|
124
|
+
});
|
|
125
|
+
} finally {
|
|
126
|
+
fs.rmSync(file, { force: true });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('discoverModuleGraph throws plain Error for a malformed graph with a trailer', () => {
|
|
131
|
+
const buf = buildSyntheticBinary({
|
|
132
|
+
modules: [{ name: '/$bunfs/root/cli', content: 'x' }],
|
|
133
|
+
entryPointId: 0,
|
|
134
|
+
});
|
|
135
|
+
const offsetsStart = buf.length - TRAILER.length - 32;
|
|
136
|
+
buf.writeUInt32LE(1, offsetsStart + 12);
|
|
137
|
+
const file = writeTempBinary(buf);
|
|
138
|
+
try {
|
|
139
|
+
assert.throws(() => discoverModuleGraph(file), (error) => {
|
|
140
|
+
assert.ok(error instanceof Error);
|
|
141
|
+
assert.equal(error instanceof ModuleGraphNotFoundError, false);
|
|
142
|
+
assert.match(error.message, /module table length is not a multiple/);
|
|
143
|
+
return true;
|
|
144
|
+
});
|
|
145
|
+
} finally {
|
|
146
|
+
fs.rmSync(file, { force: true });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
117
150
|
test('discoverModuleGraph rejects entry_point_id out of range', () => {
|
|
118
151
|
const buf = buildSyntheticBinary({
|
|
119
152
|
modules: [{ name: '/$bunfs/root/cli', content: 'x' }],
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// qle 形: X=(a,b,c)=>FN()?AR(b,c(),a):{module:b,folder:a}
|
|
3
|
+
const QLE_PATTERN_SOURCE = '(\\b[\\w$]+=\\(([\\w$]+),([\\w$]+),([\\w$]+)\\)=>)[\\w$]+\\(\\)\\?([\\w$]+)\\(\\3,\\4\\(\\),\\2\\):\\{module:\\3,folder:\\2\\}';
|
|
4
|
+
const QLE_REPLACEMENT = '$1(!0)?$5($3,$4(),$2):{module:$3,folder:$2}';
|
|
5
|
+
function countQleMatches(source) { return (source.match(new RegExp(QLE_PATTERN_SOURCE, 'g')) || []).length; }
|
|
6
|
+
function applyQlePatch(source) { return source.replace(new RegExp(QLE_PATTERN_SOURCE, 'g'), QLE_REPLACEMENT); }
|
|
7
|
+
module.exports = { QLE_PATTERN_SOURCE, QLE_REPLACEMENT, countQleMatches, applyQlePatch };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('assert/strict');
|
|
3
|
+
const { countQleMatches, applyQlePatch } = require('./hooks-standalone-pattern.js');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
test('countQleMatches finds pattern once in simple example', () => {
|
|
8
|
+
const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e};';
|
|
9
|
+
const count = countQleMatches(source);
|
|
10
|
+
assert.equal(count, 1);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('applyQlePatch replaces uu() with (!0)', () => {
|
|
14
|
+
const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e};';
|
|
15
|
+
const expected = 'var qle=(e,o,r)=>(!0)?ar(o,r(),e):{module:o,folder:e};';
|
|
16
|
+
const result = applyQlePatch(source);
|
|
17
|
+
assert.equal(result, expected);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('applyQlePatch is idempotent', () => {
|
|
21
|
+
const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e};';
|
|
22
|
+
const patched = applyQlePatch(source);
|
|
23
|
+
const repatch = applyQlePatch(patched);
|
|
24
|
+
assert.equal(repatch, patched);
|
|
25
|
+
assert.equal(countQleMatches(patched), 0);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('countQleMatches finds pattern with different minify names', () => {
|
|
29
|
+
const source = 'var vCe=(a,b,c)=>H1()?zz(b,c(),a):{module:b,folder:a};';
|
|
30
|
+
const count = countQleMatches(source);
|
|
31
|
+
assert.equal(count, 1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('applyQlePatch works with different minify names', () => {
|
|
35
|
+
const source = 'var vCe=(a,b,c)=>H1()?zz(b,c(),a):{module:b,folder:a};';
|
|
36
|
+
const expected = 'var vCe=(a,b,c)=>(!0)?zz(b,c(),a):{module:b,folder:a};';
|
|
37
|
+
const result = applyQlePatch(source);
|
|
38
|
+
assert.equal(result, expected);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('countQleMatches returns 0 for mismatched pattern (wrong field order)', () => {
|
|
42
|
+
const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:e,folder:o};'; // swapped
|
|
43
|
+
const count = countQleMatches(source);
|
|
44
|
+
assert.equal(count, 0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('countQleMatches returns 0 for import.meta.dirname only', () => {
|
|
48
|
+
const source = 'import.meta.dirname';
|
|
49
|
+
const count = countQleMatches(source);
|
|
50
|
+
assert.equal(count, 0);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('countQleMatches returns 0 for unrelated arrow function', () => {
|
|
54
|
+
const source = 'const f = (a, b, c) => someFunc() ? a : b;';
|
|
55
|
+
const count = countQleMatches(source);
|
|
56
|
+
assert.equal(count, 0);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('countQleMatches finds multiple patterns', () => {
|
|
60
|
+
const source = 'var qle=(e,o,r)=>uu()?ar(o,r(),e):{module:o,folder:e}; var qle2=(a,b,c)=>uu()?ar(b,c(),a):{module:b,folder:a};';
|
|
61
|
+
const count = countQleMatches(source);
|
|
62
|
+
assert.equal(count, 2);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('real chunk from 2.1.278 (if exists)', () => {
|
|
66
|
+
const versions = [
|
|
67
|
+
path.join(process.env.HOME || '.', '.claude-termux-native-package', 'versions', '2.1.278', 'launcher-workdir'),
|
|
68
|
+
];
|
|
69
|
+
const testRun = versions.some((vdir) => {
|
|
70
|
+
const chunks = [];
|
|
71
|
+
if (fs.existsSync(vdir)) {
|
|
72
|
+
const esmDir = fs.readdirSync(vdir).find((d) => d.startsWith('esm.'));
|
|
73
|
+
if (esmDir) {
|
|
74
|
+
const chunkDir = path.join(vdir, esmDir);
|
|
75
|
+
const chunkFile = fs.readdirSync(chunkDir).find((f) => f.match(/^chunk-7nckpqfv\.js$/));
|
|
76
|
+
if (chunkFile) {
|
|
77
|
+
const source = fs.readFileSync(path.join(chunkDir, chunkFile), 'utf8');
|
|
78
|
+
const count = countQleMatches(source);
|
|
79
|
+
assert.equal(count, 1, `chunk-7nckpqfv.js should have exactly 1 match, found ${count}`);
|
|
80
|
+
chunks.push({ file: chunkFile, count });
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
if (!testRun) {
|
|
88
|
+
test.skip();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('real chunk from 2.1.276 (if exists)', () => {
|
|
93
|
+
const versions = [
|
|
94
|
+
path.join(process.env.HOME || '.', '.claude-termux-native-package', 'versions', '2.1.276', 'launcher-workdir'),
|
|
95
|
+
];
|
|
96
|
+
const testRun = versions.some((vdir) => {
|
|
97
|
+
if (fs.existsSync(vdir)) {
|
|
98
|
+
const esmDir = fs.readdirSync(vdir).find((d) => d.startsWith('esm.'));
|
|
99
|
+
if (esmDir) {
|
|
100
|
+
const chunkDir = path.join(vdir, esmDir);
|
|
101
|
+
const chunkFile = fs.readdirSync(chunkDir).find((f) => f.match(/^chunk-0sa9p840\.js$/));
|
|
102
|
+
if (chunkFile) {
|
|
103
|
+
const source = fs.readFileSync(path.join(chunkDir, chunkFile), 'utf8');
|
|
104
|
+
const count = countQleMatches(source);
|
|
105
|
+
assert.equal(count, 1, `chunk-0sa9p840.js should have exactly 1 match, found ${count}`);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
});
|
|
112
|
+
if (!testRun) {
|
|
113
|
+
test.skip();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
@@ -718,6 +718,17 @@ async function esmChunkedMain() {
|
|
|
718
718
|
// 読み込み失敗時は空配列のまま(fail-closed、既存の同期require経路にフォールバック)
|
|
719
719
|
}
|
|
720
720
|
|
|
721
|
+
let hooksMetadata = { status: 'read-failed', patches: [] };
|
|
722
|
+
try {
|
|
723
|
+
const auditedVersionsForHooks = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'config', 'claude-native-audited-versions.json'));
|
|
724
|
+
const hooksEntry = auditedVersionsForHooks.versions?.[process.env.CURRENT_CLAUDE_VERSION];
|
|
725
|
+
if (!hooksEntry) hooksMetadata = { status: 'entry-missing', patches: [] };
|
|
726
|
+
else if (Array.isArray(hooksEntry.hooks_standalone_patches)) hooksMetadata = { status: 'ok', patches: hooksEntry.hooks_standalone_patches };
|
|
727
|
+
else hooksMetadata = { status: 'field-absent', patches: [] };
|
|
728
|
+
} catch {
|
|
729
|
+
// 既定の read-failed のまま(fail-visible: ローダーが警告する)
|
|
730
|
+
}
|
|
731
|
+
|
|
721
732
|
const loaderMod = require(path.join(libDir, 'bunfs-esm-loader.mjs'));
|
|
722
733
|
loaderMod.initialize({
|
|
723
734
|
processOwnedDir: ownedDir,
|
|
@@ -726,6 +737,7 @@ async function esmChunkedMain() {
|
|
|
726
737
|
vmGuardPath: path.join(libDir, 'bunfs-vm-guard.mjs'),
|
|
727
738
|
wsStubPath: path.join(libDir, 'bunfs-ws-stub.mjs'),
|
|
728
739
|
cycleHoists,
|
|
740
|
+
hooksMetadata,
|
|
729
741
|
reExtract: (sb, od) => extractToProcessOwnedDir(sb, od),
|
|
730
742
|
});
|
|
731
743
|
loaderMod.installFsBunfsInterception();
|
|
@@ -1768,6 +1780,17 @@ async function esmChunkedMain() {
|
|
|
1768
1780
|
// 読み込み失敗時は空配列のまま(fail-closed、既存の同期require経路にフォールバック)
|
|
1769
1781
|
}
|
|
1770
1782
|
|
|
1783
|
+
let hooksMetadata = { status: 'read-failed', patches: [] };
|
|
1784
|
+
try {
|
|
1785
|
+
const auditedVersionsForHooks = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'config', 'claude-native-audited-versions.json'));
|
|
1786
|
+
const hooksEntry = auditedVersionsForHooks.versions?.[process.env.CURRENT_CLAUDE_VERSION];
|
|
1787
|
+
if (!hooksEntry) hooksMetadata = { status: 'entry-missing', patches: [] };
|
|
1788
|
+
else if (Array.isArray(hooksEntry.hooks_standalone_patches)) hooksMetadata = { status: 'ok', patches: hooksEntry.hooks_standalone_patches };
|
|
1789
|
+
else hooksMetadata = { status: 'field-absent', patches: [] };
|
|
1790
|
+
} catch {
|
|
1791
|
+
// 既定の read-failed のまま(fail-visible: ローダーが警告する)
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1771
1794
|
const loaderMod = require(path.join(libDir, 'bunfs-esm-loader.mjs'));
|
|
1772
1795
|
loaderMod.initialize({
|
|
1773
1796
|
processOwnedDir: ownedDir,
|
|
@@ -1776,6 +1799,7 @@ async function esmChunkedMain() {
|
|
|
1776
1799
|
vmGuardPath: path.join(libDir, 'bunfs-vm-guard.mjs'),
|
|
1777
1800
|
wsStubPath: path.join(libDir, 'bunfs-ws-stub.mjs'),
|
|
1778
1801
|
cycleHoists,
|
|
1802
|
+
hooksMetadata,
|
|
1779
1803
|
reExtract: (sb, od) => extractToProcessOwnedDir(sb, od),
|
|
1780
1804
|
});
|
|
1781
1805
|
loaderMod.installFsBunfsInterception();
|
|
@@ -2241,3 +2241,85 @@ test('stableHash.xxHash64 implementation (G2 v3 implementation)', () => {
|
|
|
2241
2241
|
assert.match(testResult, /^[0-9a-z]{1,13}$/, `Bun.hash.xxHash64('x').toString(36) should match pattern in ${markerKey}, got: ${testResult}`);
|
|
2242
2242
|
}
|
|
2243
2243
|
});
|
|
2244
|
+
|
|
2245
|
+
test('hooksMetadata construction: both helper and bootstrap esmChunkedMain contain same code', () => {
|
|
2246
|
+
const fullScript = fs.readFileSync(scriptPath, 'utf8');
|
|
2247
|
+
|
|
2248
|
+
// Extract hooksMetadata construction snippets from both esmChunkedMain blocks
|
|
2249
|
+
// Pattern: "let hooksMetadata = { status: 'read-failed'..." through "} catch { ... }"
|
|
2250
|
+
const pattern = /let hooksMetadata = \{ status: 'read-failed', patches: \[\] \};[\s\S]*?} catch \{[\s\S]*?\}/g;
|
|
2251
|
+
const matches = fullScript.match(pattern);
|
|
2252
|
+
assert.equal(matches.length, 2, 'should find hooksMetadata code in both helper and bootstrap esmChunkedMain');
|
|
2253
|
+
|
|
2254
|
+
// Verify both are identical
|
|
2255
|
+
assert.equal(matches[0], matches[1], 'hooksMetadata construction should be identical in helper and bootstrap');
|
|
2256
|
+
|
|
2257
|
+
// Extract the first snippet for detailed verification
|
|
2258
|
+
const snippet = matches[0];
|
|
2259
|
+
assert.ok(snippet.includes('const auditedVersionsForHooks = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR'), 'should construct auditedVersionsForHooks');
|
|
2260
|
+
assert.ok(snippet.includes('const hooksEntry = auditedVersionsForHooks.versions?.[process.env.CURRENT_CLAUDE_VERSION]'), 'should read hooksEntry');
|
|
2261
|
+
assert.ok(snippet.includes("status: 'entry-missing'"), 'should set entry-missing status');
|
|
2262
|
+
assert.ok(snippet.includes("status: 'ok'"), 'should set ok status');
|
|
2263
|
+
assert.ok(snippet.includes("status: 'field-absent'"), 'should set field-absent status');
|
|
2264
|
+
});
|
|
2265
|
+
|
|
2266
|
+
test('hooksMetadata snippet execution: 4 status cases work correctly', () => {
|
|
2267
|
+
const fullScript = fs.readFileSync(scriptPath, 'utf8');
|
|
2268
|
+
const pattern = /let hooksMetadata = \{ status: 'read-failed', patches: \[\] \};[\s\S]*?} catch \{[\s\S]*?\}/;
|
|
2269
|
+
const match = fullScript.match(pattern);
|
|
2270
|
+
assert.ok(match, 'should find hooksMetadata snippet');
|
|
2271
|
+
|
|
2272
|
+
const snippet = match[0];
|
|
2273
|
+
|
|
2274
|
+
// Case (a): require throws exception → 'read-failed'
|
|
2275
|
+
const testFnA = new Function('require', 'path', 'process', snippet + '; return hooksMetadata;');
|
|
2276
|
+
const resultA = testFnA(
|
|
2277
|
+
() => { throw new Error('not found'); },
|
|
2278
|
+
{ join: () => 'dummy' },
|
|
2279
|
+
{ env: { CLAUDE_TERMUX_PACKAGE_DIR: 'dummy', CURRENT_CLAUDE_VERSION: '1.0.0' } }
|
|
2280
|
+
);
|
|
2281
|
+
assert.equal(resultA.status, 'read-failed');
|
|
2282
|
+
assert.deepEqual(resultA.patches, []);
|
|
2283
|
+
|
|
2284
|
+
// Case (b): hooksEntry is undefined → 'entry-missing'
|
|
2285
|
+
const testFnB = new Function('require', 'path', 'process', snippet + '; return hooksMetadata;');
|
|
2286
|
+
const resultB = testFnB(
|
|
2287
|
+
(p) => ({ versions: {} }), // no entry for version
|
|
2288
|
+
{ join: () => 'dummy' },
|
|
2289
|
+
{ env: { CLAUDE_TERMUX_PACKAGE_DIR: 'dummy', CURRENT_CLAUDE_VERSION: 'no.such.version' } }
|
|
2290
|
+
);
|
|
2291
|
+
assert.equal(resultB.status, 'entry-missing');
|
|
2292
|
+
|
|
2293
|
+
// Case (c): hooks_standalone_patches is not an array → 'field-absent'
|
|
2294
|
+
const testFnC = new Function('require', 'path', 'process', snippet + '; return hooksMetadata;');
|
|
2295
|
+
const resultC = testFnC(
|
|
2296
|
+
(p) => ({ versions: { '1.0.0': { hooks_standalone_patches: 'not_array' } } }),
|
|
2297
|
+
{ join: () => 'dummy' },
|
|
2298
|
+
{ env: { CLAUDE_TERMUX_PACKAGE_DIR: 'dummy', CURRENT_CLAUDE_VERSION: '1.0.0' } }
|
|
2299
|
+
);
|
|
2300
|
+
assert.equal(resultC.status, 'field-absent');
|
|
2301
|
+
|
|
2302
|
+
// Case (d): valid array → 'ok' with patches
|
|
2303
|
+
const testFnD = new Function('require', 'path', 'process', snippet + '; return hooksMetadata;');
|
|
2304
|
+
const patches = [{ file: 'test.js', expectedOccurrences: 1 }];
|
|
2305
|
+
const resultD = testFnD(
|
|
2306
|
+
(p) => ({ versions: { '1.0.0': { hooks_standalone_patches: patches } } }),
|
|
2307
|
+
{ join: () => 'dummy' },
|
|
2308
|
+
{ env: { CLAUDE_TERMUX_PACKAGE_DIR: 'dummy', CURRENT_CLAUDE_VERSION: '1.0.0' } }
|
|
2309
|
+
);
|
|
2310
|
+
assert.equal(resultD.status, 'ok');
|
|
2311
|
+
assert.deepEqual(resultD.patches, patches);
|
|
2312
|
+
});
|
|
2313
|
+
|
|
2314
|
+
test('hooksMetadata passed to loaderMod.initialize in both esmChunkedMain', () => {
|
|
2315
|
+
const fullScript = fs.readFileSync(scriptPath, 'utf8');
|
|
2316
|
+
|
|
2317
|
+
// Both helper and bootstrap should have loaderMod.initialize({ ... hooksMetadata, ... })
|
|
2318
|
+
const helperBlock = extractBlock('cat <<\'NODE\' > "$_helper"', '\n export ENABLE_CLAUDEAI_MCP_SERVERS=');
|
|
2319
|
+
assert.match(helperBlock, /loaderMod\.initialize\(\{[\s\S]*?hooksMetadata,[\s\S]*?\}/, 'helper: hooksMetadata should be passed to initialize');
|
|
2320
|
+
|
|
2321
|
+
// Count occurrences: should see hooksMetadata in initialize arguments
|
|
2322
|
+
const initCalls = fullScript.match(/loaderMod\.initialize\(\{/g) || [];
|
|
2323
|
+
const hooksMetadataInInit = fullScript.match(/hooksMetadata,/g) || [];
|
|
2324
|
+
assert.ok(hooksMetadataInInit.length >= 2, 'hooksMetadata should appear in at least 2 initialize calls (helper + bootstrap)');
|
|
2325
|
+
});
|