Skip to content

Scenarios

A scenario is one person’s punches, setup and policy, written in TOML. It also holds what their week, their pay period’s ledger or an export must come to. You use scenarios to prove a policy package does what you mean before you publish it. Publishing runs them on the server. It refuses a package whose scenarios fail.

A scenario passes when everything it expects matches. It fails with each difference listed. Scenarios need no database and name no tenant. They work like the scenarios protocol packages carry: facts in, expected results out. Every standard step and every cookbook recipe comes with scenarios. You can read them as worked examples.

Put a package’s scenarios in its scenarios/ folder, laid out as a policy package, and run:

Terminal window
hourctl attend test my-policies/overtime/ # a policy package and its scenarios
hourctl attend test my-policies/ # every package under it

Each scenario runs with the package published and adopted, its layers before the scenario’s own. So a scenario holds only these things:

  • The person’s facts.
  • The setup.
  • What it expects.
  • Any layer of its own that shows a variant, such as a union local with its own week or a company that pays in tenths of an hour.

A scenario can also use the standard package and any package it declares itself ([package.<name>]). hourctl attend test reaches no server. It exits 1 when a scenario fails.

Here is every key, with its default where it has one. Times are wall times in the person’s zone (zone). Durations are text ("8h", "7h 30m").

The sample shows each key once, with the form of its value. It is one scenario that hourctl attend test passes. What it expects follows from the facts and the policy it gives. There are nine hours on the Monday, and the last half hour is over the 8 h 30 m the plant-7 layer sets. Some keys have nothing to show in this scenario, such as an exception or a balance earned. For those, the value is empty and a comment gives the form of a full one. Take the keys you need. The standard steps’ and cookbook recipes’ scenarios are whole examples of the same format.

description = "Five eight-hour days"
[policy] # the first layer of the policy: scenario rev 1
zone = "America/Chicago" # the person's time zone
zones = [{ from = "2026-10-08", zone = "America/New_York" }]
# zones moved to, each from a workday on
week_starts = "monday" # settings; what none says is plain counting
day_starts = "00:00"
decimals = 2
pay_periods = { every_days = 14, from = "2026-10-05" }
# or { month_days = [1, 16] }, { starts = [...] }
categories = { work = "regular", lunch = "paid_lunch", break = "paid_break" }
shifts = { early = "30m" } # work starting that early belongs to the shift
sides = ["pay", "bill"] # default ["pay"]; a step names its side
close = { late_changes = "refuse" } # default adjust
accruals = { since = "2026-01-01" } # default: no balances
[[policy.step]] # steps of the first layer, in order
id = "daily"
uses = "standard/threshold" # <package>/<step>
params = { over = "8h", to = "overtime", window = "day" }
[[layer]] # more layers, as a tenant's are
id = "plant-7"
applies_to = "under management:ops" # whom it applies to (an
# eligibility rule); default: everyone
order = 10 # default 0: lowest first, then as written
revision = 4 # default 1
from = "2026-09-01" # default: open
to = "2026-12-31" # default: open
settings = { decimals = 3, close = { after_days = 3 } }
# as [policy] has them: categories, shifts,
# close and accruals each a table
unset = ["close.after_days"] # settings a layer before it set
locks = ["step:daily"]
[[layer.step]]
id = "daily"
change = "params" # add (default), params, replace, disable, enable
params = { over = "8h 30m" }
# uses, after, before: as for add
[package.mine] # a package for this scenario, beside the
source = "return {}" # official ones in packages/
[[published]] # a version of a policy package, published:
name = "franchise" # its layers come before the scenario's own,
version = "2.1.0" # and its steps run as franchise/<step>
effective = "2026-10-12" # default: in force from the beginning
source = "return { ... }" # no source: layers only
[[published.layer]] # its layers, as [[layer]]
id = "overtime"
locks = ["*"]
[adopt] # the packages the tenant adopts: following
franchise = "2" # a major version, or pinning one ("2.0.0")
[[dimension]] # labor context dimensions
id = "job"
required = true # default false
allowed = ["pack", "forklift"] # default: any value
[[assignment]]
id = "A12"
from = "2026-01-01" # default: open
to = "2026-12-31"
defaults = { cost_center = "4410" }
allowed = { job = ["pack"] }
organizations = { clients = "northwind-dallas" } # its own place in a
# hierarchy, where approvals of its work wait
[[implication]] # one value meaning others
when = { work_code = "7" }
then = { assignment = "A12", job = "pack" }
from = "2026-10-01" # default: open; to as well
[[shift]] # the person's scheduled shifts
id = "s1"
start = "2026-10-05 08:00"
end = "2026-10-05 16:30"
values = { assignment = "A15" }
[[shift_definition]] # shifts that repeat
id = "days"
start = "08:00"
end = "16:30" # at or before start: the next day
days = ["monday", "tuesday"]
# or every = { days = 4, from = "2026-10-01" }, or dates = ["2026-10-05"]
from = "2026-10-01" # default: open; to as well
values = { job = "pack" }
[[holiday]]
id = "thanks"
name = "Thanksgiving" # default: the id
month = 11 # with day = 25, or weekday and n (-1: last)
weekday = "thursday"
n = 4
# or date = "2026-12-24"
observed = "nearest_weekday" # default as_is
[[leave]] # a leave request
id = "v1" # default: lv1, lv2...
category = "vacation"
days = { "2026-10-06" = "8h", "2026-10-07" = "4h" }
recorded = "2026-10-01 09:00" # default: when the first day starts
# by, comment; replaces = "v0"; cancel = true (with no days)
# Its approval: [[approval]] subject = "leave:<id>:<first day>", under
# an [[approval_rule]] subject = "leave"; with none, it waits at stage "approval".
[[employment]] # a change of the person's employment
id = "e1" # default: e1, e2...
effective = "2026-01-05"
kind = "hired" # hired, terminated, leave_started,
# leave_ended, changed
attributes = { exempt = false, state = "CA", payroll_id = "E1001" }
organizations = { management = "ops-west" } # from that day ("": none)
location = "reno" # their work location from that day ("": none)
recorded = "2026-01-02 09:00" # default: when the day starts
# by, reason; replaces, void = true: as for labor
[[organization]] # an organization of a hierarchy
hierarchy = "management"
id = "ops" # a root, with no parent given
[[organization]]
hierarchy = "management"
id = "ops-east"
[[organization]]
hierarchy = "management"
id = "ops-west"
name = "Operations West" # default: the id
parent = "ops" # default: a root
moves = [{ from = "2026-10-12", parent = "ops-east" }]
# under another from a day ("": a root)
labels = { level = "team" }
metadata = { cost_center = "4410" }
[[location]] # a work location
id = "reno"
zone = "America/Los_Angeles" # days there are worked out in it
jurisdiction = "us-nv"
# name (default: the id), labels, metadata
[[schedule_override]] # one date changed
date = "2026-10-06"
kind = "leave" # off, leave, holiday, replace, extra
start = "10:00" # replace and extra: the shift
end = "18:00" # (and its values)
recorded = "2026-10-01 09:00" # default: when the workday starts
# id (default o1, o2...), by, reason
[defaults]
employee = { location = "plant-7" }
tenant = { cost_center = "1000" }
[tenant] # the tenant the scenario runs in: none is
metadata = { region = "west" } # needed; its metadata, as policies read it
# (`ctx:tenant()`)
[person] # who the person is, as the tenant keeps
id = "e1" # them: their id (default "person"),
unlinked = true # an unlinked person,
employer = "acme-ca" # or an employee of an employer,
worker = "w-17" # of a worker
[[person.other]] # the worker's other records, as last worked
person = "us-4471" # out (`ctx:other_records`)
employer = "acme-us"
days = { "2026-10-05" = { work = "6h" } }
[[category]] # pay categories (one not listed: worked, paid)
id = "paid_break"
worked = false # default true
paid = true # default true
code = "PB" # optional: its code in another system
[[measure]] # what labor entries and steps count
id = "boxes"
kind = "count" # duration, count, or money (with currency,
# decimals: default 2)
[[rate]] # rates, matched on context
kind = "pay"
matches = { assignment = "A12", job = "forklift" }
amount = 2150 # minor units
currency = "USD"
from = "2026-01-01" # default: open; to as well
[[labor]] # labor entries
workday = "2026-10-05"
measure = "boxes"
quantity = 10 # or a duration, "8h", for hours
category = "pieces"
values = { job = "pack" }
segment = "p1" # the segment it belongs to, by its first punch
replaces = "l1" # and void = true to take it away
# id (default l1, l2...), recorded (default: when the workday starts), by
[[approval_rule]] # what needs approving
subject = "day" # day, period, category:<id>, entry, leave,
# assignment
stages = ["supervisor", "payroll"]
blocked_by_exceptions = true # default false
side = "bill" # default pay
organizations = { supervisor = { hierarchy = "management", up = 0 } }
# the organization a stage waits on; with
# select = "level = department": the nearest
# from there up the selector picks
[[approval]] # a decision
subject = "bill:day:2026-10-05" # day:<day> for the pay side, period:<first day>,
# category:<id>:<day>,
# entry:<id>@<day>, leave:<id>:<first day>,
# assignment:<id>:<first day>;
# bill:day:... for the bill side
stage = "supervisor"
decision = "approve" # approve, reject, dispute
recorded = "2026-10-06 09:00"
# by, comment; fingerprint: default, the subject's as it was when recorded
[[accrual_category]] # time off earned and used
id = "pto"
uses = ["pto"] # the pay categories that draw it down
[[accrual_adjustment]] # a balance changed by hand
category = "pto"
workday = "2026-10-06"
amount = "8h" # or "-2h"
[[close]] # a pay period closed (or reopen = true)
period = "2026-10-05" # its first day
recorded = "2026-10-12 08:00"
# by
[[clock]] # time passing: the clock moves on, step by
to = "2026-10-15 00:00" # step, to an instant; the facts recorded by
# then are there, and the closes the policy's
# close.after_days makes by then are made
closed = ["2026-10-05"] # the periods closed then, by first day
# ("2026-10-05 automatic" where the policy
# closed it)
events = ["leave.requested v1", "period.closed pay 2026-10-05", "period.closed bill 2026-10-05"]
# what was told since the step before
[[punch]]
at = "2026-10-05 08:00" # wall time in the zone in force; one the
# clocks repeat is the first, unless an offset
# says: "2026-11-01 01:15 -06:00"
kind = "in" # in, out, lunch_start, lunch_end, break_start,
# break_end, transfer, unknown (the default)
values = { job = "pack" } # labor context picked with it
id = "p1" # default p1, p2... in the order written
recorded = "2026-10-06 09:00" # default: when it happened
[[correction]] # one of add, move, void, retype, set_values
id = "c1" # default c1, c2... in the order written
recorded = "2026-10-06 09:00"
by = "supervisor"
reason = "forgot to punch out"
add = { id = "p9", at = "2026-10-05 17:00", kind = "out" }
# move = { punch = "p2", to = "2026-10-05 17:00" }
# void = "p2"
# retype = { punch = "p2", kind = "out" }
# set_values = { punch = "p1", values = { job = "forklift" } }
[expect]
week = "2026-10-05" # any day of the week
worked = "9h"
days = { "2026-10-05" = "9h" } # if given, a day not listed worked none
exceptions = [] # every exception is compared: none here; one is
# { kind = "missing_out", at = "2026-10-06 08:00" },
# and detail = "..." matches its words too
hours = "9.000" # the week's decimal hours (decimals = 3 in the
# plant-7 layer), if given
lines = ["8.500", "0.500"] # each allocation's, in order, if given
segments = ["work 2026-10-05 08:00-17:00 job=pack"]
# every segment of its workdays, effective times
contexts = ["work 2026-10-05 08:00 assignment=A12 [only_assignment] cost_center=4410 [assignment:A12] job=pack [punch:p1] location=plant-7 [employee]"]
# each segment's labor context and sources
allocations = ["2026-10-05 08:00-16:30 regular 8.500 assignment=A12 cost_center=4410 job=pack location=plant-7", "2026-10-05 16:30-17:00 overtime 0.500 assignment=A12 cost_center=4410 job=pack location=plant-7"]
# every allocation, in the order paid
stamps = ["2026-10-05 16:30-17:00 overtime: daily [scenario rev 1, plant-7 rev 4]: moved 30m from regular to overtime: over 8h 30m in the day"]
# every allocation's stamps, in order
quantities = ["2026-10-05 boxes 10 pieces assignment=A12 cost_center=4410 job=pack location=plant-7"]
# every count and money line, in order
quantity_stamps = [] # none here; a step that adds money stamps its line:
# "2026-10-05 pay piece_pay: pieces [scenario rev 1]: ..."
# every count and money line's stamps, in order
# error = "words in it" # the scenario must fail with these words
[expect.period] # the ledger of the pay period a day is in
day = "2026-10-07"
side = "bill" # default pay
first = "2026-10-05" # its first and last day, if given
last = "2026-10-18"
worked = "9h" # and the rest, as above
approvals = ["bill:day:2026-10-05 pending payroll"]
# "... pending supervisor to role:hr": routed
# by a step; "... blocked (why)": blocked by one;
# "... at ops-west": the organization it waits on
approved = false # the timecard approved, as a whole or every
# assignment of it
accruals = [] # none earned here; one is "2026-10-05 pto earned 1h 20m"
balances = {} # and with it { pto = "1h 20m" }
calendar = ["2026-10-05 08:00-16:30 shift", "2026-10-05 08:00-16:30 shift", "2026-10-06 off leave", "2026-10-12 08:00-16:30 shift", "2026-10-13 08:00-16:30 shift"]
# the period's schedule, day by day
leave = ["v1 pending approval"]
# the requests with a day in it, as they stand
[expect.export] # what an exporter writes of a pay period
uses = "standard/csv" # <package>/<name>
params = { id_attribute = "payroll_id" }
day = "2026-10-05" # a day of the period
side = "bill" # default pay
person = "1001" # the person's id it is given (default person)
file = """
person,first,last,workday,category,hours
E1001,2026-10-05,2026-10-18,2026-10-05,regular,9.000
"""

Ids default to these, in the order written:

  • p1, p2… for punches.
  • c1… for corrections.
  • l1, l2… for labor entries, and lv1, lv2… for leave requests.
  • e1… for employment changes.
  • o1… for schedule overrides.
  • a1… for accrual adjustments.

[policy] is the first layer, scenario rev 1, for everyone. Each [[layer]] is a layer as a tenant’s is (policy layers). It applies to the person by its applies_to on each day. In a [[layer]], settings takes categories, shifts, close and accruals as tables, as [policy] does.

An approval’s subject names a day, so its fingerprint can be worked out as it was when it was recorded. An entry’s subject is entry:<id>@<day>. A leave request’s is leave:<id>:<first day>. Its fingerprint is the request’s own (leave).

[expect] is about the week week is in. [expect.period] is about the ledger of the pay period day is in, on side (default pay). [expect.export] is about what an exporter writes of a pay period. Only what is given is compared, except exceptions. Every exception is listed, and a week or period without exceptions expects none. A scenario that should fail says so with error = "words in it" in [expect]. It passes when the engine stops with an error containing them.

KeyEach entry, as written
worked, paidThe total worked time ("40h") and decimal hours in paid categories ("40.00").
days{ "2026-10-05" = "8h" }: worked time by day. A day not listed worked none.
linesEach allocation’s decimal hours, in the order paid: "0.33".
segmentswork 2026-10-05 08:00-12:00 job=pack: kind, effective span, values.
contextswork 2026-10-05 08:00 assignment=A12 [only_assignment]: each segment’s context, each value with its source.
allocations2026-10-05 08:00-12:00 regular 4.00 assignment=A12: span (or untimed), category, hours, context.
stamps2026-10-16 12:00-13:00 overtime: weekly [[email protected]/company rev 1, local-42 rev 2]: moved 1h from work to overtime: over 36h in the week.
quantities2026-10-05 boxes 10 pieces job=pack: workday, measure, quantity, category, context.
quantity_stamps2026-10-05 pay piece_pay: pieces [scenario rev 1]: added 250 pay in piece_pay: 10 boxes at 25. It gives the workday, measure, category, and the note of the rule that added or changed it.
exceptions{ kind = "missing_out", at = "2026-10-06 08:00" }.
approvalsday:2026-10-05 approved (a period only).
approvedWhether the timecard is approved, as a whole or every assignment of it (a period only).
accruals, balances2026-10-05 pto earned 1h 20m; { pto = "1h 20m" } (a period only).
calendar2026-10-05 08:00-16:30 shift, 2026-10-06 off leave, 2026-11-26 holiday thanks (a period only).
fileWhat the exporter writes, whole (an export only).

Use [[clock]] steps to test what happens as time passes, such as a period closing on its own. The clock moves forward to each step’s instant in turn, never back. At each step, the facts recorded by then are present. The closes the policy’s close.after_days makes by then are made, as on a server (period close). A step lists two things. One is the periods closed by then (automatic where the policy closed them). The other is the events since the step before:

[[clock]]
to = "2026-10-15 00:00"
closed = ["2026-10-05 automatic"]
events = ["period.closed pay 2026-10-05"]
[[clock]]
to = "2026-10-16 10:00"
events = ["period.adjusted pay 2026-10-12 for 2026-10-05 8.00"]

An event is written as its kind and what it is about. That is a timecard’s side and first day, an adjustment’s period and hours, an exception’s kind and instant, or a leave request’s id. [expect] then checks the state the last clock step left. The cookbook’s automatic close recipe shows it.

The scenario catalogue lists every scenario that ships with Time and Attendance, by the rule it proves. Each is a complete example of the format.