import { Given, When, Then } from '@cucumber/cucumber';
import assert from 'node:assert/strict';
import path from 'node:path';
import { access } from 'node:fs/promises';
import { loadSkillFromFile, type LoadedSkill } from '../../src/runtime/skill_loader';
// State for Skill Loading
let registryRoot: string | undefined;
let loaded: LoadedSkill | undefined;
// Helper to check file existence
async function fileExists(p: string): Promise<boolean> {
try {
await access(p);
return true;
} catch {
return false;
}
}
Given('the skill registry path is {string}', function (p: string) {
registryRoot = p;
});
When('the dispatcher requests {string}', async function (skillId: string) {
assert.ok(registryRoot, 'registryRoot must be set');
loaded = await loadSkillFromFile(registryRoot, skillId);
});
Then('the system loads the file {string}', async function (relPath: string) {
const full = path.join(process.cwd(), relPath);
const ok = await fileExists(full);
assert.equal(ok, true, `Expected file to exist: ${full}`);
assert.ok(loaded, 'skill should have been loaded');
assert.equal(path.normalize(loaded.sourcePath), path.normalize(relPath));
});
Then('the parsed Boundary name should be {string}', function (expected: string) {
assert.ok(loaded, 'skill should have been loaded');
assert.equal(loaded.name, expected);
});
Then('the parsed Kernel should contain {string}', function (snippet: string) {
assert.ok(loaded, 'skill should have been loaded');
assert.ok(loaded.kernel.includes(snippet), `Kernel did not contain expected snippet: ${snippet}`);
});
Then('the Allowed Tools list should be empty', function () {
assert.ok(loaded, 'skill should have been loaded');
assert.deepEqual(loaded.allowedTools, []);
});
// NOTE: Other feature step definitions live elsewhere or are intentionally unimplemented in the walking skeleton.