mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
70b1145b5e
* refactor: remove version field from GenerateOutcome and EarlyHint All consumers are in the same repo and evolve together — version field adds ceremony without practical value at this stage. Keeps schema_version in VerifiedArtifactMetadata (sidecar file format). * refactor: migrate all 123 CLI adapters from YAML to TypeScript Remove YAML as an adapter format entirely. All adapters now use TypeScript with cli() from @jackwener/opencli/registry. - Convert 123 YAML adapter files to TypeScript via batch script - Remove YAML scanning from discovery.ts (registerYamlCli, yaml import) - Remove scanYaml() and shouldReplaceManifestEntry() from build-manifest.ts - Change synthesize.ts to output JSON candidates (internal format) - Change generate-verified.ts to write .ts adapter files instead of .yaml - Delete yaml-schema.ts (dead code) and scripts/yaml-to-ts.mjs (one-time tool) - Update all tests to match new format Closes discussion in #OpenCLI thread 47ddba82. * fix: close YAML migration gaps in plugin scaffold, validation, and scan - plugin-scaffold.ts: generate hello.ts (TS pipeline) instead of hello.yaml - plugin.ts validatePluginStructure: no longer accept .yaml as valid command file - plugin.ts scanPluginCommands: remove .yaml/.yml from scanned extensions - discovery.ts: add explicit log.warn() when YAML files detected in clis/ or plugins/ - plugin.test.ts: update all test fixtures from .yaml to .js - plugin-scaffold.test.ts: update hello.yaml references to hello.ts - Delete dead src/yaml-schema.ts Resolves PR #887 review blockers from @mbp-codex-pr0. * refactor: complete YAML removal across docs, skills, record, and binance adapters Code changes: - record.ts: candidate output changed from .yaml (yaml.dump) to .json (JSON.stringify), removed js-yaml import - src/clis/binance: convert all 11 YAML adapters to TypeScript cli() format - binance/commands.test.ts: rewrite to use registry instead of yaml.load - skill-generate.test.ts, diagnostic.test.ts: update mock paths from .yaml to .ts - build-manifest.ts, synthesize.ts: update stale YAML comments Documentation: - README.md: remove .yaml from Dynamic Loader, fix plugin types, fix synthesize comment - README.zh-CN.md: fix synthesize comment - CONTRIBUTING.md: replace YAML Adapter section with Pipeline Adapter (TS), update arg examples - docs/developer/yaml-adapter.md: replaced with deprecation redirect - docs/developer/architecture.md: remove YAML pipeline references - docs/developer/contributing.md: remove YAML adapter section - docs/developer/ai-workflow.md: YAML → TS in synthesize description - docs/guide/getting-started.md: remove .yaml from loader, update engine description - docs/guide/plugins.md: remove YAML plugin option, update plugin types - docs/index.md, docs/comparison.md: remove YAML adapter references - docs/zh/guide/plugins.md: remove .yaml from scan description Skills: - opencli-explorer/SKILL.md: rewrite YAML vs TS decision tree to TS-only - opencli-oneshot/SKILL.md: replace YAML templates with TS cli() templates - opencli-generate/SKILL.md: YAML artifact path → TS artifact path - opencli-usage/SKILL.md, plugins.md: update adapter format references * fix: clean up remaining YAML adapter references in docs - docs/zh/guide/plugins.md: replace YAML plugin example with TS pipeline - docs/developer/testing.md: YAML Adapter heading → Adapter, remove validate line - TESTING.md: same fix in root testing doc - CONTRIBUTING.md: remove "YAML validation" comment - docs/.vitepress/config.mts: mark YAML Adapter Guide as (Deprecated) in nav - docs/advanced/download.md: remove "YAML Adapters" from pipeline step heading
99 lines
3.6 KiB
TypeScript
99 lines
3.6 KiB
TypeScript
/**
|
|
* Tests for plugin scaffold: create new plugin directories.
|
|
*/
|
|
|
|
import { describe, it, expect, afterEach } from 'vitest';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
import { createPluginScaffold } from './plugin-scaffold.js';
|
|
|
|
describe('createPluginScaffold', () => {
|
|
const createdDirs: string[] = [];
|
|
|
|
afterEach(() => {
|
|
for (const dir of createdDirs) {
|
|
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
|
|
}
|
|
createdDirs.length = 0;
|
|
});
|
|
|
|
it('creates all expected files', () => {
|
|
const dir = path.join(os.tmpdir(), `opencli-scaffold-${Date.now()}`);
|
|
createdDirs.push(dir);
|
|
|
|
const result = createPluginScaffold('my-test', { dir });
|
|
expect(result.name).toBe('my-test');
|
|
expect(result.dir).toBe(dir);
|
|
expect(result.files).toContain('opencli-plugin.json');
|
|
expect(result.files).toContain('package.json');
|
|
expect(result.files).toContain('hello.ts');
|
|
expect(result.files).toContain('greet.ts');
|
|
expect(result.files).toContain('README.md');
|
|
|
|
// All files exist
|
|
for (const f of result.files) {
|
|
expect(fs.existsSync(path.join(dir, f))).toBe(true);
|
|
}
|
|
});
|
|
|
|
it('generates valid opencli-plugin.json', () => {
|
|
const dir = path.join(os.tmpdir(), `opencli-scaffold-${Date.now()}`);
|
|
createdDirs.push(dir);
|
|
|
|
createPluginScaffold('test-manifest', { dir, description: 'Test desc' });
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'opencli-plugin.json'), 'utf-8'));
|
|
expect(manifest.name).toBe('test-manifest');
|
|
expect(manifest.version).toBe('0.1.0');
|
|
expect(manifest.description).toBe('Test desc');
|
|
expect(manifest.opencli).toMatch(/^>=/);
|
|
});
|
|
|
|
it('generates ESM package.json', () => {
|
|
const dir = path.join(os.tmpdir(), `opencli-scaffold-${Date.now()}`);
|
|
createdDirs.push(dir);
|
|
|
|
createPluginScaffold('test-pkg', { dir });
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
|
|
expect(pkg.type).toBe('module');
|
|
expect(pkg.peerDependencies?.['@jackwener/opencli']).toBeDefined();
|
|
});
|
|
|
|
it('generates a TS sample that matches the current plugin API', () => {
|
|
const dir = path.join(os.tmpdir(), `opencli-scaffold-${Date.now()}`);
|
|
createdDirs.push(dir);
|
|
|
|
createPluginScaffold('test-ts', { dir });
|
|
const tsSample = fs.readFileSync(path.join(dir, 'greet.ts'), 'utf-8');
|
|
|
|
expect(tsSample).toContain(`import { cli, Strategy } from '@jackwener/opencli/registry';`);
|
|
expect(tsSample).toContain(`strategy: Strategy.PUBLIC`);
|
|
expect(tsSample).toContain(`help: 'Name to greet'`);
|
|
expect(tsSample).toContain(`func: async (_page, kwargs)`);
|
|
expect(tsSample).not.toContain('async run(');
|
|
});
|
|
|
|
it('documents a supported local install flow', () => {
|
|
const dir = path.join(os.tmpdir(), `opencli-scaffold-${Date.now()}`);
|
|
createdDirs.push(dir);
|
|
|
|
createPluginScaffold('test-readme', { dir });
|
|
const readme = fs.readFileSync(path.join(dir, 'README.md'), 'utf-8');
|
|
|
|
expect(readme).toContain(`opencli plugin install file://${dir}`);
|
|
});
|
|
|
|
it('rejects invalid names', () => {
|
|
expect(() => createPluginScaffold('Bad_Name')).toThrow('Invalid plugin name');
|
|
expect(() => createPluginScaffold('123start')).toThrow('Invalid plugin name');
|
|
});
|
|
|
|
it('rejects non-empty directory', () => {
|
|
const dir = path.join(os.tmpdir(), `opencli-scaffold-${Date.now()}`);
|
|
createdDirs.push(dir);
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
fs.writeFileSync(path.join(dir, 'existing.txt'), 'x');
|
|
expect(() => createPluginScaffold('test', { dir })).toThrow('not empty');
|
|
});
|
|
});
|