Skip to content

Commit a7b0486

Browse files
committed
feat: change nnc to string
1 parent 8dc1ad8 commit a7b0486

File tree

5 files changed

+74
-9
lines changed

5 files changed

+74
-9
lines changed

packages/homestar/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"esbuild": "^0.20.1",
7575
"esbuild-plugin-replace-regex": "^0.0.2",
7676
"get-tsconfig": "^4.7.3",
77-
"iso-base": "^2.0.1",
77+
"iso-base": "^3.0.0",
7878
"just-kebab-case": "^4.2.0",
7979
"multiformats": "^13.1.0",
8080
"object-path": "^0.11.8",
@@ -83,7 +83,7 @@
8383
"devDependencies": {
8484
"@types/get-value": "^3.0.5",
8585
"@types/json-templates": "^3.0.3",
86-
"@types/node": "^20.11.25",
86+
"@types/node": "^20.11.26",
8787
"@types/object-path": "^0.11.4",
8888
"execa": "^8.0.1",
8989
"homestar-runtime": "rc",
@@ -92,7 +92,7 @@
9292
"playwright-test": "^14.1.1",
9393
"tempy": "^3.1.0",
9494
"testcontainers": "^10.7.2",
95-
"type-fest": "^4.11.1",
95+
"type-fest": "^4.12.0",
9696
"unws": "^0.2.4",
9797
"ws": "^8.16.0"
9898
},

packages/homestar/src/schemas.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export const Receipt = z.object({
6262
export const Task = z.object({
6363
op: z.string(),
6464
rsc: z.string().url(),
65-
nnc: z.union([
66-
z.string().length(0),
67-
z.object({ '/': z.object({ bytes: z.string() }) }),
68-
]),
65+
/**
66+
* Base 32 hex (lower) encoded random bytes, either 12 or 16 bytes long
67+
*/
68+
nnc: z.string(),
6969
input: z.object({
7070
func: z.string(),
7171
args: z.array(z.any()),

packages/homestar/src/workflow/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export function invocation(opts) {
280280
args: opts.args,
281281
func: opts.func,
282282
},
283-
nnc: '',
283+
nnc: opts.nnc ?? '',
284284
op: 'wasm/run',
285285
rsc: opts.resource,
286286
},

packages/homestar/src/workflow/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export interface InvocationOptions<Args extends any[] = any[]> {
5353
args: Args
5454
func: string
5555
resource: Resource
56+
/**
57+
* Base 32 hex (lower) encoded random bytes, either 12 or 16 bytes long
58+
*/
59+
nnc?: string
5660
}
5761

5862
export interface TemplateOptions<

packages/homestar/test/wasmify.node.test.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as url from 'url'
22
import path from 'path'
33
import { assert, suite } from 'playwright-test/taps'
44
import pDefer from 'p-defer'
5-
import { base64 } from 'iso-base/rfc4648'
5+
import { base32hex, base64 } from 'iso-base/rfc4648'
66
import { utf8 } from 'iso-base/utf8'
7+
import { randomBytes } from 'iso-base/crypto'
78
import { temporaryDirectory } from 'tempy'
89
import { WebsocketTransport } from '@fission-codes/channel/transports/ws.js'
910
import { build } from '../src/wasmify/index.js'
@@ -152,3 +153,63 @@ test(
152153
timeout: 120_000,
153154
}
154155
)
156+
157+
test(
158+
'should wasmify with multiple tasks and nonce',
159+
async function () {
160+
const { outPath } = await build({
161+
entryPoint: path.join(__dirname, 'fixtures', 'wasmify', 'hello.ts'),
162+
outDir,
163+
})
164+
165+
/** @type {import('p-defer').DeferredPromise<string>} */
166+
const prom = pDefer()
167+
168+
const args = ['hello', 1]
169+
170+
const wasmCID = await addFSFileToIPFS(outPath)
171+
const workflow1 = await workflow({
172+
name: 'sum',
173+
workflow: {
174+
tasks: [
175+
invocation({
176+
name: 'sum1',
177+
func: 'sum',
178+
args,
179+
resource: `ipfs://${wasmCID}`,
180+
nnc: base32hex.encode(randomBytes(12), false),
181+
}),
182+
invocation({
183+
name: 'sum2',
184+
func: 'sum',
185+
args: ['{{needs.sum1.output}}', 2],
186+
resource: `ipfs://${wasmCID}`,
187+
nnc: base32hex.encode(randomBytes(12), false),
188+
}),
189+
],
190+
},
191+
})
192+
193+
/**
194+
* @type {number}
195+
*/
196+
let count = 0
197+
const { error } = await hs.runWorkflow(workflow1, (data) => {
198+
count++
199+
200+
if (count === 2) {
201+
prom.resolve(data.receipt.out[1])
202+
}
203+
})
204+
205+
if (error) {
206+
return assert.fail(error)
207+
}
208+
209+
const r = await prom.promise
210+
assert.equal(r, 'hello12')
211+
},
212+
{
213+
timeout: 30_000,
214+
}
215+
)

0 commit comments

Comments
 (0)