This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

vit / test / remix.test.js
3.2 kB 70 lines
1// SPDX-License-Identifier: MIT 2// Copyright (c) 2026 sol pbc 3 4import { describe, test, expect } from 'bun:test'; 5import { run } from './helpers.js'; 6import { mkdirSync, writeFileSync, rmSync } from 'node:fs'; 7import { tmpdir } from 'node:os'; 8import { join } from 'node:path'; 9 10const agentEnv = { CLAUDECODE: '1' }; 11 12describe('vit remix', () => { 13 test('rejects when run outside a coding agent', () => { 14 const result = run('remix fast-cache-invalidation', '/tmp', { CLAUDECODE: '', GEMINI_CLI: '', CODEX_CI: '' }); 15 expect(result.exitCode).not.toBe(0); 16 expect(result.stderr).toContain('should be run by a coding agent'); 17 }); 18 19 test('fails with no arguments', () => { 20 const result = run('remix', '/tmp', agentEnv); 21 expect(result.exitCode).not.toBe(0); 22 }); 23 24 test('rejects invalid ref format', () => { 25 const result = run('remix not-valid', '/tmp', agentEnv); 26 expect(result.exitCode).not.toBe(0); 27 expect(result.stderr).toContain('invalid ref'); 28 }); 29 30 test('errors when no DID configured', () => { 31 const configHome = join(tmpdir(), '.test-remix-config-' + Math.random().toString(36).slice(2)); 32 mkdirSync(configHome, { recursive: true }); 33 const result = run('remix fast-cache-invalidation', '/tmp', { ...agentEnv, XDG_CONFIG_HOME: configHome }); 34 expect(result.exitCode).not.toBe(0); 35 expect(result.stderr).toContain('no DID configured'); 36 rmSync(configHome, { recursive: true, force: true }); 37 }); 38 39 test('errors when no beacon is set', () => { 40 const result = run('remix fast-cache-invalidation --did did:plc:test123', '/tmp', agentEnv); 41 expect(result.exitCode).not.toBe(0); 42 expect(result.stderr).toContain('no beacon set'); 43 }); 44 45 // --- trust gate tests --- 46 47 describe('trust gate', () => { 48 test('untrusted ref without dangerous-accept: error includes hint', () => { 49 const tmp = join(tmpdir(), '.test-remix-trust-' + Math.random().toString(36).slice(2)); 50 mkdirSync(join(tmp, '.vit'), { recursive: true }); 51 writeFileSync(join(tmp, '.vit', 'config.json'), JSON.stringify({ beacon: 'vit:github.com/test/test' })); 52 const result = run('remix fast-cache-invalidation --did did:plc:test123', tmp, agentEnv); 53 expect(result.exitCode).toBe(1); 54 expect(result.stderr).toContain('not trusted'); 55 expect(result.stderr).toContain('vit vet --dangerous-accept --confirm'); 56 rmSync(tmp, { recursive: true, force: true }); 57 }); 58 59 test('untrusted ref with active dangerous-accept: bypasses trust gate', () => { 60 const tmp = join(tmpdir(), '.test-remix-bypass-' + Math.random().toString(36).slice(2)); 61 mkdirSync(join(tmp, '.vit'), { recursive: true }); 62 writeFileSync(join(tmp, '.vit', 'config.json'), JSON.stringify({ beacon: 'vit:github.com/test/test' })); 63 writeFileSync(join(tmp, '.vit', 'dangerous-accept'), JSON.stringify({ acceptedAt: '2026-03-26T14:30:00.000Z' })); 64 const result = run('remix fast-cache-invalidation --did did:plc:test123', tmp, agentEnv); 65 // Should bypass trust check — will fail later at auth/network, NOT at trust 66 expect(result.stderr).not.toContain('not trusted'); 67 rmSync(tmp, { recursive: true, force: true }); 68 }); 69 }); 70});