mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-10 23:00:34 +00:00
update
This commit is contained in:
1 parent
b5023799d3
commit
1fb668064e
8 files changed
+422
-38
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import { cmdInit } from '../src/ops.mjs';
|
||||
import { runDoctorChecks, cmdDoctor } from '../src/cmd-doctor.mjs';
|
||||
|
||||
const MOCK_CONFIG = {
|
||||
installDir: 'torch',
|
||||
namespace: 'doctor-test-namespace',
|
||||
hashtag: 'doctor-test-hashtag',
|
||||
relays: ['wss://relay.damus.io'],
|
||||
};
|
||||
|
||||
test('runDoctorChecks reports failure when TORCH is not installed', async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'torch-doctor-missing-'));
|
||||
|
||||
const report = runDoctorChecks({ cwd: root, nodeVersion: '22.10.0' });
|
||||
assert.equal(report.ok, false);
|
||||
assert.ok(report.checks.some((check) => check.id === 'install-detection' && check.status === 'fail'));
|
||||
});
|
||||
|
||||
test('runDoctorChecks passes core checks after init', async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'torch-doctor-healthy-'));
|
||||
await cmdInit(false, root, MOCK_CONFIG);
|
||||
|
||||
// Simulate post-init dependency install for health check.
|
||||
await fs.mkdir(path.join(root, 'torch', 'node_modules'), { recursive: true });
|
||||
|
||||
const report = runDoctorChecks({ cwd: root, nodeVersion: '22.10.0' });
|
||||
assert.equal(report.ok, true);
|
||||
assert.ok(report.checks.some((check) => check.id === 'memory-hook' && check.status === 'pass'));
|
||||
assert.ok(report.checks.some((check) => check.id === 'install-files' && check.status === 'pass'));
|
||||
});
|
||||
|
||||
test('runDoctorChecks fails when memory hook is missing from existing AGENTS.md', async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'torch-doctor-hook-missing-'));
|
||||
await cmdInit(false, root, MOCK_CONFIG);
|
||||
|
||||
await fs.writeFile(path.join(root, 'AGENTS.md'), '# AGENTS\nNo memory section.\n', 'utf8');
|
||||
|
||||
const report = runDoctorChecks({ cwd: root, nodeVersion: '22.10.0' });
|
||||
assert.equal(report.ok, false);
|
||||
const memoryCheck = report.checks.find((check) => check.id === 'memory-hook');
|
||||
assert.ok(memoryCheck);
|
||||
assert.equal(memoryCheck.status, 'fail');
|
||||
});
|
||||
|
||||
test('cmdDoctor emits JSON report when requested', async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'torch-doctor-json-'));
|
||||
await cmdInit(false, root, MOCK_CONFIG);
|
||||
|
||||
const logs = [];
|
||||
const report = cmdDoctor({
|
||||
cwd: root,
|
||||
json: true,
|
||||
nodeVersion: '22.10.0',
|
||||
log: (line) => logs.push(String(line)),
|
||||
});
|
||||
|
||||
assert.ok(report.summary.passed >= 1);
|
||||
assert.equal(logs.length, 1);
|
||||
assert.doesNotThrow(() => JSON.parse(logs[0]));
|
||||
});
|
||||
@@ -193,3 +193,37 @@ test('cmdInit creates torch-config.json with random namespace', async () => {
|
||||
'weekly handoff command should be configured for host installs',
|
||||
);
|
||||
});
|
||||
|
||||
test('cmdInit upserts TORCH memory integration into existing AGENTS.md and CLAUDE.md', async () => {
|
||||
const projectRoot = path.join(tempBase, 'project_memory_hook_init');
|
||||
fs.mkdirSync(projectRoot, { recursive: true });
|
||||
|
||||
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
||||
const claudePath = path.join(projectRoot, 'CLAUDE.md');
|
||||
fs.writeFileSync(agentsPath, '# Team Policy\n\nKeep tests strict.\n', 'utf8');
|
||||
fs.writeFileSync(claudePath, '# Local Guidance\n\nFollow repo conventions.\n', 'utf8');
|
||||
|
||||
await cmdInit(false, projectRoot, MOCK_CONFIG);
|
||||
|
||||
const agentsContent = fs.readFileSync(agentsPath, 'utf8');
|
||||
const claudeContent = fs.readFileSync(claudePath, 'utf8');
|
||||
assert.ok(agentsContent.includes('## TORCH Memory Integration'), 'AGENTS.md should include memory heading');
|
||||
assert.ok(claudeContent.includes('## TORCH Memory Integration'), 'CLAUDE.md should include memory heading');
|
||||
assert.ok(agentsContent.includes('Keep tests strict.'), 'AGENTS.md existing content should be preserved');
|
||||
assert.ok(claudeContent.includes('Follow repo conventions.'), 'CLAUDE.md existing content should be preserved');
|
||||
});
|
||||
|
||||
test('cmdUpdate keeps TORCH memory integration idempotent', async () => {
|
||||
const projectRoot = path.join(tempBase, 'project_memory_hook_update');
|
||||
fs.mkdirSync(projectRoot, { recursive: true });
|
||||
|
||||
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
||||
fs.writeFileSync(agentsPath, '# Agent Rules\n', 'utf8');
|
||||
|
||||
await cmdInit(false, projectRoot, MOCK_CONFIG);
|
||||
await cmdUpdate(false, projectRoot);
|
||||
|
||||
const agentsContent = fs.readFileSync(agentsPath, 'utf8');
|
||||
const headingMatches = agentsContent.match(/## TORCH Memory Integration/g) ?? [];
|
||||
assert.strictEqual(headingMatches.length, 1, 'Memory integration block should not be duplicated');
|
||||
});
|
||||
Reference in new issue
Block a user