Skip to content
Open
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
45 changes: 45 additions & 0 deletions packages/taco/scripts/validate-conditions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env npx tsx
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hashbang #!/usr/bin/env npx tsx is not a valid/portable shebang: most kernels pass everything after /usr/bin/env as a single argument, so env will look for an executable literally named "npx tsx" and the script won’t be runnable when invoked directly. Consider either removing the shebang (since the documented invocation is via pnpm tsx ...) or switching to a portable form like using env -S to split arguments (and ensuring the repo’s supported platforms include it).

Suggested change
#!/usr/bin/env npx tsx

Copilot uses AI. Check for mistakes.
/**
* Validates conditions.json against the TACo SDK schemas
* This helps identify client-side validation errors vs server-side errors
*
* Usage: tsx scripts/validate-conditions.ts [path/to/conditions.json]
*/

import * as fs from 'fs';
import * as path from 'path';

import { ConditionExpression } from '../src/conditions/condition-expr';

async function main() {
const conditionsPath = path.resolve(process.argv[2] ?? 'conditions.json');
console.log(`Loading conditions from: ${conditionsPath}`);

const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8');
const conditionsObj = JSON.parse(conditionsJson);

console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));

Comment on lines +21 to +23
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description/test plan says the script prints the parsed conditionType on success, but the script currently always prints the full loaded conditions JSON (and additional status lines). If the docs are going to reference this as a canonical helper, consider minimizing default stdout to just the conditionType (and/or gating the full JSON dump behind a --verbose flag) so the output matches the documented behavior and is easier to script against.

Copilot uses AI. Check for mistakes.
console.log('\n--- Validating with TACo SDK ---\n');

try {
Comment on lines +18 to +26
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors from readFileSync/JSON.parse (missing file, invalid JSON) occur before the try/catch, and the final main().catch(console.error) will log them but still exit with status 0. This contradicts the documented behavior of exiting 1 on invalid input. Wrap the file read/parse in the same try/catch (or set process.exitCode = 1 in the top-level catch) so any failure results in a non-zero exit status.

Suggested change
const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8');
const conditionsObj = JSON.parse(conditionsJson);
console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));
console.log('\n--- Validating with TACo SDK ---\n');
try {
try {
const conditionsJson = fs.readFileSync(conditionsPath, 'utf-8');
const conditionsObj = JSON.parse(conditionsJson);
console.log('\nConditions loaded:');
console.log(JSON.stringify(conditionsObj, null, 2));
console.log('\n--- Validating with TACo SDK ---\n');

Copilot uses AI. Check for mistakes.
const expr = ConditionExpression.fromObj(conditionsObj);
console.log('✅ Conditions are VALID according to TACo SDK!');
console.log('\nParsed condition type:', expr.condition.conditionType);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('\nParsed condition type:', expr.condition.conditionType);
console.log('\nParsed condition type:', expr.condition.value.conditionType);

} catch (error) {
console.error('❌ Conditions are INVALID according to TACo SDK!');
// Write full error to file
const errorStr = error instanceof Error
? `${error.name}: ${error.message}\n\nStack: ${error.stack}`
: JSON.stringify(error, null, 2);
const errorPath = `${conditionsPath}.error.txt`;
fs.writeFileSync(errorPath, errorStr);
console.error(`\nFull error written to: ${errorPath}`);
console.error('\nError message:', error instanceof Error ? error.message : String(error));

process.exit(1);
}
}

main().catch(console.error);
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If main() rejects, main().catch(console.error) logs the error but does not set a failing exit code, so CI/consumers will see a successful exit even though validation didn’t run. Set process.exitCode = 1 (or call process.exit(1)) in this catch handler after logging.

Suggested change
main().catch(console.error);
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

Copilot uses AI. Check for mistakes.
Loading