@bash0816/claude-code 2.1.150 → 2.1.153-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.
@@ -1,310 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const test = require('node:test');
5
- const assert = require('node:assert/strict');
6
- const EventEmitter = require('events');
7
-
8
- const {
9
- BLOCK_MESSAGE,
10
- createGuardedChildProcess,
11
- shouldBlockCommand,
12
- shouldBlockExecString,
13
- } = require('./native-update-guard.js');
14
-
15
- test('blocks npm install of official package', () => {
16
- assert.equal(
17
- shouldBlockCommand('npm', ['install', '-g', '@anthropic-ai/claude-code@latest']),
18
- true,
19
- );
20
- });
21
-
22
- test('blocks npm update of official package via absolute npm path', () => {
23
- assert.equal(
24
- shouldBlockCommand('/usr/bin/npm', ['update', '-g', '@anthropic-ai/claude-code']),
25
- true,
26
- );
27
- });
28
-
29
- test('does not block canonical package install', () => {
30
- assert.equal(
31
- shouldBlockCommand('npm', ['install', '-g', '@bash0816/claude-code@2.1.137']),
32
- false,
33
- );
34
- });
35
-
36
- test('blocks exec string that installs official package', () => {
37
- assert.equal(
38
- shouldBlockExecString('npm install -g @anthropic-ai/claude-code@latest'),
39
- true,
40
- );
41
- });
42
-
43
- test('does not block unrelated exec string', () => {
44
- assert.equal(
45
- shouldBlockExecString('npm install -g @bash0816/claude-code@2.1.137'),
46
- false,
47
- );
48
- });
49
-
50
- test('blocks env npm install of official package', () => {
51
- assert.equal(
52
- shouldBlockCommand('env', ['FOO=bar', 'npm', 'install', '-g', '@anthropic-ai/claude-code@latest']),
53
- true,
54
- );
55
- });
56
-
57
- test('blocks npx official package invocation', () => {
58
- assert.equal(shouldBlockCommand('npx', ['@anthropic-ai/claude-code']), true);
59
- });
60
-
61
- test('blocks npx package option official package invocation', () => {
62
- assert.equal(shouldBlockCommand('npx', ['-p', '@anthropic-ai/claude-code', 'claude']), true);
63
- assert.equal(shouldBlockCommand('npx', ['--package=@anthropic-ai/claude-code', 'claude']), true);
64
- });
65
-
66
- test('blocks pnpm add of official package', () => {
67
- assert.equal(
68
- shouldBlockCommand('pnpm', ['add', '-g', '@anthropic-ai/claude-code']),
69
- true,
70
- );
71
- });
72
-
73
- test('blocks yarn global add of official package', () => {
74
- assert.equal(
75
- shouldBlockCommand('yarn', ['global', 'add', '@anthropic-ai/claude-code']),
76
- true,
77
- );
78
- });
79
-
80
- test('blocks corepack pnpm add of official package', () => {
81
- assert.equal(
82
- shouldBlockCommand('corepack', ['pnpm', 'add', '-g', '@anthropic-ai/claude-code']),
83
- true,
84
- );
85
- });
86
-
87
- test('blocks corepack yarn global add of official package', () => {
88
- assert.equal(
89
- shouldBlockCommand('corepack', ['yarn', 'global', 'add', '@anthropic-ai/claude-code']),
90
- true,
91
- );
92
- });
93
-
94
- test('does not block corepack pnpm add of canonical package', () => {
95
- assert.equal(
96
- shouldBlockCommand('corepack', ['pnpm', 'add', '-g', '@bash0816/claude-code@2.1.137']),
97
- false,
98
- );
99
- });
100
-
101
- test('blocks exec string through env npm', () => {
102
- assert.equal(
103
- shouldBlockExecString('env FOO=bar npm install -g @anthropic-ai/claude-code@latest'),
104
- true,
105
- );
106
- });
107
-
108
- test('blocks exec string through corepack yarn', () => {
109
- assert.equal(
110
- shouldBlockExecString('corepack yarn global add @anthropic-ai/claude-code'),
111
- true,
112
- );
113
- });
114
-
115
- test('blocks exec string through sh -c npm install', () => {
116
- assert.equal(
117
- shouldBlockExecString('sh -c "npm install -g @anthropic-ai/claude-code"'),
118
- true,
119
- );
120
- });
121
-
122
- test('blocks exec string through bash -lc pnpm add', () => {
123
- assert.equal(
124
- shouldBlockExecString('bash -lc "pnpm add -g @anthropic-ai/claude-code"'),
125
- true,
126
- );
127
- });
128
-
129
- test('does not block canonical exec string through bash -lc', () => {
130
- assert.equal(
131
- shouldBlockExecString('bash -lc "npm install -g @bash0816/claude-code@2.1.137"'),
132
- false,
133
- );
134
- });
135
-
136
- test('does not block unrelated shell exec string', () => {
137
- assert.equal(shouldBlockExecString('sh -c "echo ok"'), false);
138
- });
139
-
140
- function createRealChildStub() {
141
- const calls = [];
142
- return {
143
- calls,
144
- spawn(...args) {
145
- calls.push(['spawn', args]);
146
- return { kind: 'spawn', args };
147
- },
148
- execFile(...args) {
149
- calls.push(['execFile', args]);
150
- return { kind: 'execFile', args };
151
- },
152
- exec(...args) {
153
- calls.push(['exec', args]);
154
- return { kind: 'exec', args };
155
- },
156
- spawnSync(...args) {
157
- calls.push(['spawnSync', args]);
158
- return { kind: 'spawnSync', args, status: 0 };
159
- },
160
- execFileSync(...args) {
161
- calls.push(['execFileSync', args]);
162
- return Buffer.from('ok');
163
- },
164
- execSync(...args) {
165
- calls.push(['execSync', args]);
166
- return Buffer.from('ok');
167
- },
168
- };
169
- }
170
-
171
- test('guarded spawn blocks official npm update without delegating', async () => {
172
- const writes = [];
173
- const realChild = createRealChildStub();
174
- const guarded = createGuardedChildProcess(realChild, value => writes.push(value));
175
-
176
- const child = guarded.spawn('npm', ['install', '-g', '@anthropic-ai/claude-code@latest']);
177
- assert.equal(child instanceof EventEmitter, true);
178
-
179
- const result = await new Promise(resolve => {
180
- child.once('close', (code, signal) => resolve({ code, signal }));
181
- });
182
-
183
- assert.deepEqual(result, { code: 1, signal: null });
184
- assert.deepEqual(realChild.calls, []);
185
- assert.equal(writes[0], `${BLOCK_MESSAGE}\n`);
186
- });
187
-
188
- test('guarded spawn delegates canonical install', () => {
189
- const realChild = createRealChildStub();
190
- const guarded = createGuardedChildProcess(realChild, () => {});
191
- const result = guarded.spawn('npm', ['install', '-g', '@bash0816/claude-code@2.1.137']);
192
-
193
- assert.equal(result.kind, 'spawn');
194
- assert.equal(realChild.calls.length, 1);
195
- });
196
-
197
- test('guarded execFile blocks official npm update callback path', async () => {
198
- const writes = [];
199
- const realChild = createRealChildStub();
200
- const guarded = createGuardedChildProcess(realChild, value => writes.push(value));
201
-
202
- const callbackResult = await new Promise(resolve => {
203
- guarded.execFile(
204
- 'npm',
205
- ['update', '-g', '@anthropic-ai/claude-code'],
206
- (error, stdout, stderr) => resolve({ error, stdout, stderr }),
207
- );
208
- });
209
-
210
- assert.equal(callbackResult.error.code, 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED');
211
- assert.equal(callbackResult.stdout, '');
212
- assert.equal(callbackResult.stderr, `${BLOCK_MESSAGE}\n`);
213
- assert.deepEqual(realChild.calls, []);
214
- assert.equal(writes[0], `${BLOCK_MESSAGE}\n`);
215
- });
216
-
217
- test('guarded exec blocks official npm update shell string', async () => {
218
- const realChild = createRealChildStub();
219
- const guarded = createGuardedChildProcess(realChild, () => {});
220
-
221
- const callbackResult = await new Promise(resolve => {
222
- guarded.exec(
223
- 'npm install -g @anthropic-ai/claude-code@latest',
224
- (error, stdout, stderr) => resolve({ error, stdout, stderr }),
225
- );
226
- });
227
-
228
- assert.equal(callbackResult.error.code, 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED');
229
- assert.equal(callbackResult.stdout, '');
230
- assert.equal(callbackResult.stderr, `${BLOCK_MESSAGE}\n`);
231
- assert.deepEqual(realChild.calls, []);
232
- });
233
-
234
- test('guarded spawnSync blocks official npm update with status 1', () => {
235
- const writes = [];
236
- const realChild = createRealChildStub();
237
- const guarded = createGuardedChildProcess(realChild, value => writes.push(value));
238
- const result = guarded.spawnSync('npm', ['update', '-g', '@anthropic-ai/claude-code']);
239
-
240
- assert.equal(result.status, 1);
241
- assert.equal(Buffer.isBuffer(result.stderr), true);
242
- assert.equal(String(result.stderr), `${BLOCK_MESSAGE}\n`);
243
- assert.equal(result.error.code, 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED');
244
- assert.deepEqual(realChild.calls, []);
245
- assert.equal(writes[0], `${BLOCK_MESSAGE}\n`);
246
- });
247
-
248
- test('guarded execFileSync throws on official npm update', () => {
249
- const realChild = createRealChildStub();
250
- const guarded = createGuardedChildProcess(realChild, () => {});
251
-
252
- assert.throws(
253
- () => guarded.execFileSync('npm', ['install', '-g', '@anthropic-ai/claude-code@latest']),
254
- error => error && error.code === 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED',
255
- );
256
- assert.deepEqual(realChild.calls, []);
257
- });
258
-
259
- test('guarded execSync throws on official npm update shell string', () => {
260
- const realChild = createRealChildStub();
261
- const guarded = createGuardedChildProcess(realChild, () => {});
262
-
263
- assert.throws(
264
- () => guarded.execSync('npm update -g @anthropic-ai/claude-code'),
265
- error => error && error.code === 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED',
266
- );
267
- assert.deepEqual(realChild.calls, []);
268
- });
269
-
270
- test('guarded spawn blocks official npm update through sh -c', async () => {
271
- const writes = [];
272
- const realChild = createRealChildStub();
273
- const guarded = createGuardedChildProcess(realChild, value => writes.push(value));
274
-
275
- const child = guarded.spawn('/bin/sh', ['-c', 'npm install -g @anthropic-ai/claude-code']);
276
- const result = await new Promise(resolve => {
277
- child.once('close', (code, signal) => resolve({ code, signal }));
278
- });
279
-
280
- assert.deepEqual(result, { code: 1, signal: null });
281
- assert.deepEqual(realChild.calls, []);
282
- assert.equal(writes[0], `${BLOCK_MESSAGE}\n`);
283
- });
284
-
285
- test('guarded execFile blocks official update through bash -lc', async () => {
286
- const realChild = createRealChildStub();
287
- const guarded = createGuardedChildProcess(realChild, () => {});
288
-
289
- const callbackResult = await new Promise(resolve => {
290
- guarded.execFile(
291
- '/usr/bin/bash',
292
- ['-lc', 'pnpm add -g @anthropic-ai/claude-code'],
293
- (error, stdout, stderr) => resolve({ error, stdout, stderr }),
294
- );
295
- });
296
-
297
- assert.equal(callbackResult.error.code, 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED');
298
- assert.equal(callbackResult.stdout, '');
299
- assert.equal(callbackResult.stderr, `${BLOCK_MESSAGE}\n`);
300
- assert.deepEqual(realChild.calls, []);
301
- });
302
-
303
- test('guarded spawn delegates canonical shell install', () => {
304
- const realChild = createRealChildStub();
305
- const guarded = createGuardedChildProcess(realChild, () => {});
306
- const result = guarded.spawn('/bin/sh', ['-c', 'npm install -g @bash0816/claude-code@2.1.137']);
307
-
308
- assert.equal(result.kind, 'spawn');
309
- assert.equal(realChild.calls.length, 1);
310
- });