Download test/loop-cli.test.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/test/loop-cli.test.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/test/loop-cli.test.js
-
curl -L -o loop-cli.test.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/test/loop-cli.test.js
2.38 kB
| /** | |
| * loop-cli.test.js โ BADA Loop CLI ๋ฐ HUD ๋จ์ ํ ์คํธ | |
| * | |
| * ๋์: src/cli/loop-cli.js (formatLoopHUD, listLoops, resumeLoop) | |
| * ๊ท์ฝ: MoAI-ADK TDD, SPEC-ACT-001 v1.0.0 | |
| */ | |
| const { test, describe } = require('node:test'); | |
| const assert = require('node:assert/strict'); | |
| const db = require('../knowledge-db'); | |
| const { formatLoopHUD, listLoops, resumeLoop } = require('../src/cli/loop-cli'); | |
| const { LoopController } = require('../src/loop-controller'); | |
| describe('BADA Loop CLI & HUD Test', () => { | |
| test('formatLoopHUD should render correct ASCII status string', () => { | |
| const run = { | |
| run_id: 'run_abc12345', | |
| goal_name: 'Battery Optimization', | |
| status: 'paused', | |
| total_iterations: 3, | |
| total_cost: 0.125, | |
| last_error: 'Temperature too high' | |
| }; | |
| const goal = { max_iterations: 10, token_budget: 5.0 }; | |
| const hud = formatLoopHUD(run, goal); | |
| assert.ok(hud.includes('PAUSED')); | |
| assert.ok(hud.includes('Battery Optimization')); | |
| assert.ok(hud.includes('Iter: 3/10')); | |
| assert.ok(hud.includes('$0.1250/$5.00')); | |
| assert.ok(hud.includes('Temperature too high')); | |
| }); | |
| test('resumeLoop should restore LoopController from DB record', async () => { | |
| const testRunId = `cli_test_run_${Date.now()}`; | |
| const testGoalId = `cli_test_goal_${Date.now()}`; | |
| // SQLite ์ธ๋ ํค ๊ณ์ฝ์ ๋ง๊ฒ ์คํ์ ๋ถ๋ชจ ๋ชฉํ๋ฅผ ๋จผ์ ์ ์ฅํ๋ค. | |
| db.saveLoopGoal('default', { id: testGoalId, name: 'CLI recovery fixture', | |
| goal_expression: [{ type: 'metric_threshold', metric_key: 'pass', value: true }] }); | |
| db.saveLoopRun({ | |
| run_id: testRunId, | |
| goal_id: testGoalId, | |
| status: 'paused', | |
| total_iterations: 1, | |
| total_cost: 0.05, | |
| total_tokens_used: 500, | |
| started_at: new Date(Date.now() - 5000).toISOString() | |
| }); | |
| db.saveLoopIteration({ | |
| id: `${testRunId}_iter_1`, | |
| loop_run_id: testRunId, | |
| iteration_number: 1, | |
| status: 'completed', | |
| cost: 0.05, | |
| tokens_used: 500, | |
| step_outputs: { pass: true } | |
| }); | |
| const controller = await resumeLoop(testRunId, { | |
| logStream: { write: () => {} } | |
| }); | |
| assert.ok(controller instanceof LoopController); | |
| assert.equal(controller.circuitBreaker.currentIteration, 1); | |
| assert.ok(Math.abs(controller.circuitBreaker.cumulativeCost - 0.05) < 1e-6); | |
| }); | |
| }); | |