Skip to content

Commit 47d55ef

Browse files
committed
Fix test.
1 parent 950c492 commit 47d55ef

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import chalk from 'chalk';
55
import { stdin as input, stdout as output } from 'node:process';
66
import { createInterface } from 'readline/promises';
77
import { unitsToAmount } from '@oceanprotocol/lib';
8+
import { toBoolean } from './helpers.js';
89

910
async function initializeSigner() {
1011

@@ -194,15 +195,14 @@ export async function createCLI() {
194195
.option('--maxJobDuration <maxJobDuration>', 'Compute maxJobDuration')
195196
.option('-t, --token <paymentToken>', 'Compute payment token')
196197
.option('--resources <resources>', 'Compute resources')
197-
.option('--accept [boolean]', 'Automatically approve payment and start job without prompt', true)
198+
.option('--accept [boolean]', 'Auto-confirm payment for compute job (true/false)', toBoolean)
198199
.action(async (datasetDids, algoDid, computeEnvId, maxJobDuration, paymentToken, resources, options) => {
199200
const dsDids = options.datasets || datasetDids;
200201
const aDid = options.algo || algoDid;
201202
const envId = options.env || computeEnvId;
202203
const jobDuration = options.maxJobDuration || maxJobDuration;
203204
const token = options.token || paymentToken;
204205
const res = options.resources || resources;
205-
console.log(`proceed: `, options.accept);
206206
if (!dsDids || !aDid ||!envId || !jobDuration || !token || !res) {
207207
console.error(chalk.red('Missing required arguments'));
208208
// process.exit(1);

src/helpers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,13 @@ export function fixAndParseProviderFees(rawString: string) {
396396
.replace(/:true/g, ':true');
397397

398398
return JSON.parse(fixed);
399+
}
400+
401+
export function toBoolean(value) {
402+
if (typeof value === 'boolean') return value;
403+
if (typeof value === 'string') {
404+
const val = value.trim().toLowerCase();
405+
return val === 'true' || val === '1' || val === 'yes' || val === 'y';
406+
}
407+
return Boolean(value);
399408
}

test/paidComputeFlow.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe("Ocean CLI Paid Compute", function() {
173173
}
174174
]
175175
const paymentToken = getAddresses().Ocean
176-
const output = await runCommand(`npm run cli startCompute ${computeDatasetDid} ${jsAlgoDid} ${computeEnvId} 900 ${paymentToken} '${JSON.stringify(resources)}' --accept true`);
176+
const output = await runCommand(`npm run cli -- startCompute ${computeDatasetDid} ${jsAlgoDid} ${computeEnvId} 900 ${paymentToken} '${JSON.stringify(resources)}' --accept true`);
177177
const jobIdMatch = output.match(/JobID:\s*([^\s]+)/);
178178
const agreementIdMatch = output.match(/Agreement ID:\s*([^\s]+)/);
179179

0 commit comments

Comments
 (0)