Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"scripts": {
"build": "tsc",
"test": "node --import tsx --test test/portable-name-validation.test.ts",
"dev": "tsx src/cli.ts",
"prepublishOnly": "npm run build",
"clean": "rm -rf dist"
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/portable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export class PortableAdapter implements Adapter {
if (!ir.identity.name) {
issues.push({ severity: 'error', field: 'identity.name', message: 'name is required' });
}
if (!/^[a-z][a-z0-9-]*$/.test(ir.identity.name)) {
if (!/^[a-z0-9][a-z0-9-]*$/.test(ir.identity.name)) {
issues.push({
severity: 'error',
field: 'identity.name',
message: 'name must be lowercase a-z + hyphens',
message: 'name must be lowercase a-z, 0-9 + hyphens',
});
}
if (!ir.identity.description.full) {
Expand Down
2 changes: 1 addition & 1 deletion src/ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface SkillIR {
}

export interface Identity {
/** Skill name. lowercase a-z + hyphens. Must match directory name. */
/** Skill name. Lowercase letters, numbers, and hyphens. Must match directory name. */
name: string;

description: {
Expand Down
31 changes: 31 additions & 0 deletions test/portable-name-validation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { PortableAdapter } from '../src/adapters/portable.js';
import { emptyIR } from '../src/ir.js';

const adapter = new PortableAdapter();

function validateName(name: string) {
const ir = emptyIR(name);
ir.identity.description.full = 'A test skill.';
return adapter.validate(ir);
}

test('accepts numeric-leading portable skill names such as 4up', () => {
const result = validateName('4up');

assert.equal(result.ok, true);
assert.deepEqual(result.issues, []);
});

test('continues rejecting invalid portable skill names', () => {
for (const name of ['Uppercase', 'has_underscore', 'has space', '']) {
const result = validateName(name);

assert.equal(result.ok, false, `expected ${JSON.stringify(name)} to be rejected`);
assert.ok(
result.issues.some((issue) => issue.field === 'identity.name'),
`expected an identity.name issue for ${JSON.stringify(name)}`
);
}
});