DiscoveryVIP

Input and output

Open live editor

Discover → Predict → Understand

What evidence shows that input and output keeps state and application behavior understandable?

Input crosses a boundary before it becomes trusted application data. Trim a title and explicitly report whether it can enter state.

  1. Explain the operation and its responsibility.
  2. Predict actual values before execution.
  3. Identify local calculation, actual DOM and external execution boundaries.

Conceptual application flow

  1. User intent
  2. Action / handler
  3. Business logic
  4. State
  5. Render / persistence

Five source examples

Working contract

Input crosses a boundary before it becomes trusted application data. Trim a title and explicitly report whether it can enter state.

async function main(input) {
return {title:input.title.trim(),valid:input.title.trim().length>0};
}

Input

{
  "title": " Learn "
}

Fixed expected result

{
  "title": "Learn",
  "valid": true
}
Observe input preservation

The wrapper records the original input and compares it after the operation. Some lessons intentionally demonstrate mutation in a local copy.

async function calculate(input){
return {title:input.title.trim(),valid:input.title.trim().length>0};
}
async function main(input){const before=structuredClone(input);const result=await calculate(input);return {result,inputUnchanged:JSON.stringify(input)===JSON.stringify(before)};}

Input

{
  "title": " Learn "
}

Fixed expected result

{
  "result": {
    "title": "Learn",
    "valid": true
  },
  "inputUnchanged": true
}
Investigate the discarded result

An early return bypasses the intended operation. Repair the first incorrect boundary rather than changing the expected result.

async function calculate(input){
return {title:input.title.trim(),valid:input.title.trim().length>0};
}
async function main(input){return null; // Deliberate early return discards calculation
return await calculate(input);}

Input

{
  "title": " Learn "
}

Fixed expected result

{
  "title": "Learn",
  "valid": true
}
Repeat the deterministic calculation

Invoke the same declared pure/model operation twice and compare both results. This is not an external idempotency guarantee.

async function calculate(input){
return {title:input.title.trim(),valid:input.title.trim().length>0};
}
async function main(input){return [await calculate(structuredClone(input)),await calculate(structuredClone(input))];}

Input

{
  "title": " Learn "
}

Fixed expected result

[
  {
    "title": "Learn",
    "valid": true
  },
  {
    "title": "Learn",
    "valid": true
  }
]
Frozen regression contract

Execute the operation and compare with a fixed fixture result. Changing the calculation must not silently rewrite the expectation.

async function calculate(input){
return {title:input.title.trim(),valid:input.title.trim().length>0};
}
async function main(input){const actual=await calculate(input);const expected={"title":"Learn","valid":true};if(JSON.stringify(actual)!==JSON.stringify(expected))throw Error("Regression contract mismatch");return {pass:true,actual};}

Input

{
  "title": " Learn "
}

Fixed expected result

{
  "pass": true,
  "actual": {
    "title": "Learn",
    "valid": true
  }
}

Important operations

[
  {
    "line": 1,
    "source": "async function main(input) {",
    "explanation": "Declare the named operation or local value and follow its scope in the source."
  },
  {
    "line": 2,
    "source": "return {title:input.title.trim(),valid:input.title.trim().length>0};",
    "explanation": "Return the observable result for the caller; rendering and external effects belong to explicit boundaries."
  },
  {
    "line": 3,
    "source": "}",
    "explanation": "Declare the named operation or local value and follow its scope in the source."
  }
]

Guided mission

  1. Discover the problem and inspect source/input.
  2. Write a prediction. Run the actual source and inspect the returned value.
  3. Change one requirement and state the new expected result independently.
  4. Load the repair exercise, reproduce the failure and use hints.
  5. Restore the authored fixture and Check, then explain and extend.

Three hints

  1. Locate the input, transition and returned result before editing.
  2. Compare the first differing field and trace which expression produced it.
  3. Remove the deliberate early return and restore the named responsibility; compare with Finished Code only after trying.

Complete solution

async function main(input) {
return {title:input.title.trim(),valid:input.title.trim().length>0};
}

Common mistake: Changing the expected result to match a defect instead of repairing the behavior.

Invalid JSON is rejected before execution. Syntax and thrown errors are shown. Model kernels for DOM, HTTP and Node teach contracts; use the actual browser and exported server projects for those execution boundaries.

Reflect and extend

Which returned value or actual DOM observation supports your explanation? Which side effect was outside this check?

Create a second normal, boundary and invalid case. Write exact expected values before execution and explain what the provided fixture does not prove.

AI prompt goals

  1. Explain the current source, input, actual output and architecture boundary.
  2. Help refactor one responsibility while preserving independently expected behavior.
  3. Investigate the current error and propose normal, boundary and invalid tests.