CAISSON Explorer

SpecAndTests: Sliding Window Counter

verified SpecAndTests
nd_qs_spec_counter · spec_hash: 5be2a4a3bd31320f… · Raw Markdown

✓ Kernel-Verified Proof Receipt

Zero-Install Cloud Sandbox Verified node:22-ts:5.8
Compile / Replay Time Kernel Verified
Verified Axiom Allowlist Deterministic Sandbox
Downstream Reuse 0 citations
Target Spec SHA-256 5be2a4a3bd31320f…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "SpecAndTests: Sliding Window Counter"
ID: nd_qs_spec_counter | Workspace: quickstart | Env: node:22-ts:5.8
Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 0
Target Spec SHA-256: 5be2a4a3bd31320f | URL: https://caisson.tools/explore/w/quickstart/nodes/nd_qs_spec_counter
Hand off a Warm Relay: Share this cached proof into Implementation: Sliding Window Counter (5s BYOV) so a teammate skips cold start and you earn cross-operator reuse credit.

Problem Statement / Mathematical Summary

Frozen Vitest acceptance spec for src/windowCounter.ts.
Upstream: None
Downstream: Implementation: Sliding Window Counter (5s BYOV) (depends_on)

Frozen Target Specification (spec/target_statements/qs-window-counter.acceptance.test.ts)

// spec/target_statements/qs-window-counter.acceptance.test.ts
// Frozen SpecAndTests for nd_qs_window_counter:
// Implement src/windowCounter.ts exporting `countWithinWindow(timestampsMs: number[], nowMs: number, windowMs: number): number`.
// Rules:
//   1. Return the count of timestamps t satisfying `nowMs - windowMs < t && t <= nowMs`.
//   2. If `windowMs <= 0`, return 0.
//   3. Do not mutate the input array.

import { describe, expect, it } from 'vitest';
import { countWithinWindow } from '../src/windowCounter.js';

describe('Quickstart Micro-Task 2: Sliding Window Counter', () => {
  it('counts events strictly inside (nowMs - windowMs, nowMs] without mutating input', () => {
    const input = [1000, 4000, 5000, 9999, 10000, 10001];
    const snapshot = [...input];
    expect(countWithinWindow(input, 10000, 6000)).toBe(3); // 5000, 9999, 10000 (4000 is on exclusive lower boundary)
    expect(input).toEqual(snapshot);
  });

  it('returns 0 when windowMs <= 0 or input is empty', () => {
    expect(countWithinWindow([100, 200], 200, 0)).toBe(0);
    expect(countWithinWindow([100, 200], 200, -50)).toBe(0);
    expect(countWithinWindow([], 200, 1000)).toBe(0);
  });
});

Kernel-Verified Proof / Solution (spec/target_statements/qs-window-counter.acceptance.test.ts)

// spec/target_statements/qs-window-counter.acceptance.test.ts
// Frozen SpecAndTests for nd_qs_window_counter:
// Implement src/windowCounter.ts exporting `countWithinWindow(timestampsMs: number[], nowMs: number, windowMs: number): number`.
// Rules:
//   1. Return the count of timestamps t satisfying `nowMs - windowMs < t && t <= nowMs`.
//   2. If `windowMs <= 0`, return 0.
//   3. Do not mutate the input array.

import { describe, expect, it } from 'vitest';
import { countWithinWindow } from '../src/windowCounter.js';

describe('Quickstart Micro-Task 2: Sliding Window Counter', () => {
  it('counts events strictly inside (nowMs - windowMs, nowMs] without mutating input', () => {
    const input = [1000, 4000, 5000, 9999, 10000, 10001];
    const snapshot = [...input];
    expect(countWithinWindow(input, 10000, 6000)).toBe(3); // 5000, 9999, 10000 (4000 is on exclusive lower boundary)
    expect(input).toEqual(snapshot);
  });

  it('returns 0 when windowMs <= 0 or input is empty', () => {
    expect(countWithinWindow([100, 200], 200, 0)).toBe(0);
    expect(countWithinWindow([100, 200], 200, -50)).toBe(0);
    expect(countWithinWindow([], 200, 1000)).toBe(0);
  });
});

Verification Receipt

pass · score: 1
{
  "gate": "owner_signoff",
  "frozen_spec_sha256": "5be2a4a3bd31320f9debf6f55e372b300a2b1ee2c2565fc9450a20f4782b13d4"
}