Skip to content

MaarkssDN/Birthub-360 / .agents/skills/async-ordering-tests

async-ordering-tests

Verified

Test async ordering - event-loop / queue / channel ordering assertions, JS Promise microtask vs macrotask ordering, Python `asyncio.gather` vs `asyncio.wait_for` semantics, Go goroutine + channel happens-before relationships, async/await re-entrancy. Use deterministic schedulers (sinon fake timers, asyncio test mode) to remove run-to-run variance. Use when a callback fires twice, a later response overwrites an earlier one, or a cancelled parent task leaves a child still running - bugs where completion order, not shared memory, is the defect.

evals/microtask-before-macrotask/task.md

View on GitHub
# Subscribers must see a change before it is persisted

## Problem Description

`src/store.js` batches state changes. Subscribers are notified on the
microtask queue so the UI updates in the same tick, while persistence is
deferred to a macrotask so it never blocks rendering.

That ordering is a real guarantee - a persistence hook that reads the store
must never run before subscribers have observed the change - and it is
entirely untested. Several changes in the same tick are also supposed to
coalesce into a single notification.

## Output Specification

Add `src/store.test.js` proving the ordering guarantee between notification
and persistence, and proving that multiple changes in one tick produce one
notification.

Run `npm test` before you finish; it must pass.

Leave `src/store.basic.test.js` in place.

## Input Files

Extract the following files before beginning.

=============== FILE: package.json ===============
{
  "name": "state-core",
  "version": "1.1.0",
  "private": true,
  "scripts": {
    "test": "node --test"
  }
}

=============== FILE: src/store.js ===============
'use strict';

function createStore(initial) {
  let state = initial;
  const subscribers = [];
  const persisted = [];
  let scheduled = false;

  function schedule() {
    if (scheduled) {
      return;
    }
    scheduled = true;
    queueMicrotask(() => {
      scheduled = false;
      for (const subscriber of subscribers) {
        subscriber(state);
      }
    });
    setTimeout(() => {
      persisted.push(state);
    }, 0);
  }

  return {
    setState(next) {
      state = next;
      schedule();
    },
    subscribe(fn) {
      subscribers.push(fn);
      return () => {
        const index = subscribers.indexOf(fn);
        if (index >= 0) {
          subscribers.splice(index, 1);
        }
      };
    },
    persistedValues() {
      return persisted.slice();
    },
    read() {
      return state;
    },
  };
}

module.exports = { createStore };

=============== FILE: src/store.basic.test.js ===============
'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const { createStore } = require('./store');

test('reads back the value that was set', () => {
  const store = createStore(0);
  store.setState(7);
  assert.equal(store.read(), 7);
});
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall