mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo-client.git
synced 2026-09-22 01:02:03 -07:00
Implements the post-memo behavior slice per specs/post-memo.feature: - src/services/memo-post.js: compose, validate (empty/length), and broadcast a Memo post OP_RETURN (0x6d02) via the minimal-slp-wallet adapter surface. - Stands up the Babashka APS acceptance pipeline (entrypoint generator, runtime, regex step handlers, convenience runner). - Adds focused unit tests for the memo behavior. By coder.
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
/*
|
|
Acceptance runtime for psf-memo-client.
|
|
|
|
Expands each scenario (and each example row) from parser JSON IR into
|
|
scenario executions, prepends background steps, and dispatches every step to
|
|
the project step handlers. Unsupported steps, invalid example values, or
|
|
failed assertions fail that execution.
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const { createWorld, handleStep } = require('./handlers')
|
|
|
|
// Expand the IR scenarios into concrete executions.
|
|
// For scenario outlines with examples, one execution per example row; for
|
|
// scenarios without examples, one execution with an empty example store.
|
|
function expandScenarios (ir) {
|
|
const executions = []
|
|
const background = ir.background || []
|
|
|
|
for (const scenario of ir.scenarios) {
|
|
const examples = (scenario.examples && scenario.examples.length > 0)
|
|
? scenario.examples.map((example, i) => ({ example, suffix: `example_${i + 1}` }))
|
|
: [{ example: {}, suffix: 'example_1' }]
|
|
|
|
for (const { example, suffix } of examples) {
|
|
executions.push({
|
|
name: `${scenario.name}/${suffix}`,
|
|
steps: [...background, ...scenario.steps],
|
|
example
|
|
})
|
|
}
|
|
}
|
|
|
|
return executions
|
|
}
|
|
|
|
// Run a full feature and return a report of scenario outcomes.
|
|
async function runFeature (ir) {
|
|
const executions = expandScenarios(ir)
|
|
const results = []
|
|
let failures = 0
|
|
|
|
for (const ex of executions) {
|
|
// A fresh world/state object for each scenario execution.
|
|
const world = createWorld()
|
|
let failure = null
|
|
|
|
for (const step of ex.steps) {
|
|
try {
|
|
await handleStep(step, ex.example, world)
|
|
} catch (err) {
|
|
failure = err.message
|
|
break
|
|
}
|
|
}
|
|
|
|
if (failure) {
|
|
failures++
|
|
results.push({ name: ex.name, status: 'failed', detail: failure })
|
|
} else {
|
|
results.push({ name: ex.name, status: 'passed' })
|
|
}
|
|
}
|
|
|
|
return { feature: ir.name, results, failures, total: results.length }
|
|
}
|
|
|
|
module.exports = { expandScenarios, runFeature }
|