Skip to content
Merged
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
38 changes: 38 additions & 0 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,44 @@ describe('Action', () => {
});
});

describe('nested metadata validation', () => {
const metadata = {
name: 'Fixture action',
description: 'Fixture description',
runs: { using: 'node24', main: 'index.js' },
};

it.each([
{ inputs: { option: null } },
{ inputs: { option: 42 } },
{ inputs: { option: { description: 42 } } },
{ outputs: { result: null } },
{ outputs: { result: { description: false } } },
{ inputs: 'not a mapping' },
])('rejects malformed nested metadata through YAML loading: %j', async (nested) => {
vi.mocked(fs.readFileSync).mockReturnValueOnce(YAML.stringify({ ...metadata, ...nested }));
const { default: Action } = await import('../src/Action.js');
expect(() => new Action(actTestYmlPath, mockLogTask)).toThrow('Invalid action metadata syntax');
});

it('accepts scalar defaults and nullish descriptions through YAML loading', async () => {
vi.mocked(fs.readFileSync).mockReturnValueOnce(YAML.stringify({
Comment thread
Jamie-BitFlight marked this conversation as resolved.
...metadata,
inputs: {
enabled: { description: 'Enabled', default: false, required: false },
retries: { description: 'Retries', default: 3 },
optional: { default: null, description: null },
},
outputs: { result: { description: null } },
}));
const { default: Action } = await import('../src/Action.js');
const action = new Action(actTestYmlPath, mockLogTask);
expect(action.inputs?.enabled?.default).toBe(false);
expect(action.inputs?.retries?.default).toBe(3);
expect(action.outputs?.result?.description).toBeNull();
});
});

describe('inputDefault', () => {
it('should return the default value for an input', async () => {
const { default: Action } = await import('../src/Action.js');
Expand Down
13 changes: 13 additions & 0 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ export default class Action implements ActionYaml {
return false;
}
const record = obj as Record<string, unknown>;
const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === 'object' && value !== null && !Array.isArray(value);
const validDescriptions = (value: unknown): boolean =>
value === undefined ||
(isRecord(value) &&
Object.values(value).every(
(entry) =>
isRecord(entry) &&
(entry.description == null || typeof entry.description === 'string'),
));
if (!validDescriptions(record.inputs) || !validDescriptions(record.outputs)) {
return false;
}
if ('name' in record && 'description' in record && 'runs' in record) {
const runs = record.runs;
if (typeof runs === 'object' && runs !== null && !Array.isArray(runs) && 'using' in runs) {
Expand Down
Loading