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.
Running them
Section titled “Running them”Put a package’s scenarios in its scenarios/ folder, laid out as a policy package, and run:
hourctl attend test my-policies/overtime/ # a policy package and its scenarioshourctl attend test my-policies/ # every package under itEach 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.
The format
Section titled “The format”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 1zone = "America/Chicago" # the person's time zonezones = [{ from = "2026-10-08", zone = "America/New_York" }] # zones moved to, each from a workday onweek_starts = "monday" # settings; what none says is plain countingday_starts = "00:00"decimals = 2pay_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 shiftsides = ["pay", "bill"] # default ["pay"]; a step names its sideclose = { late_changes = "refuse" } # default adjustaccruals = { since = "2026-01-01" } # default: no balances
[[policy.step]] # steps of the first layer, in orderid = "daily"uses = "standard/threshold" # <package>/<step>params = { over = "8h", to = "overtime", window = "day" }
[[layer]] # more layers, as a tenant's areid = "plant-7"applies_to = "under management:ops" # whom it applies to (an # eligibility rule); default: everyoneorder = 10 # default 0: lowest first, then as writtenrevision = 4 # default 1from = "2026-09-01" # default: opento = "2026-12-31" # default: opensettings = { decimals = 3, close = { after_days = 3 } } # as [policy] has them: categories, shifts, # close and accruals each a tableunset = ["close.after_days"] # settings a layer before it setlocks = ["step:daily"][[layer.step]]id = "daily"change = "params" # add (default), params, replace, disable, enableparams = { over = "8h 30m" }# uses, after, before: as for add
[package.mine] # a package for this scenario, beside thesource = "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 beginningsource = "return { ... }" # no source: layers only[[published.layer]] # its layers, as [[layer]]id = "overtime"locks = ["*"]
[adopt] # the packages the tenant adopts: followingfranchise = "2" # a major version, or pinning one ("2.0.0")
[[dimension]] # labor context dimensionsid = "job"required = true # default falseallowed = ["pack", "forklift"] # default: any value
[[assignment]]id = "A12"from = "2026-01-01" # default: opento = "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 otherswhen = { work_code = "7" }then = { assignment = "A12", job = "pack" }from = "2026-10-01" # default: open; to as well
[[shift]] # the person's scheduled shiftsid = "s1"start = "2026-10-05 08:00"end = "2026-10-05 16:30"values = { assignment = "A15" }
[[shift_definition]] # shifts that repeatid = "days"start = "08:00"end = "16:30" # at or before start: the next daydays = ["monday", "tuesday"]# or every = { days = 4, from = "2026-10-01" }, or dates = ["2026-10-05"]from = "2026-10-01" # default: open; to as wellvalues = { job = "pack" }
[[holiday]]id = "thanks"name = "Thanksgiving" # default: the idmonth = 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 requestid = "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 employmentid = "e1" # default: e1, e2...effective = "2026-01-05"kind = "hired" # hired, terminated, leave_started, # leave_ended, changedattributes = { 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 hierarchyhierarchy = "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 idparent = "ops" # default: a rootmoves = [{ from = "2026-10-12", parent = "ops-east" }] # under another from a day ("": a root)labels = { level = "team" }metadata = { cost_center = "4410" }
[[location]] # a work locationid = "reno"zone = "America/Los_Angeles" # days there are worked out in itjurisdiction = "us-nv"# name (default: the id), labels, metadata
[[schedule_override]] # one date changeddate = "2026-10-06"kind = "leave" # off, leave, holiday, replace, extrastart = "10:00" # replace and extra: the shiftend = "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 ismetadata = { region = "west" } # needed; its metadata, as policies read it # (`ctx:tenant()`)
[person] # who the person is, as the tenant keepsid = "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 workedperson = "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 truepaid = true # default truecode = "PB" # optional: its code in another system
[[measure]] # what labor entries and steps countid = "boxes"kind = "count" # duration, count, or money (with currency, # decimals: default 2)
[[rate]] # rates, matched on contextkind = "pay"matches = { assignment = "A12", job = "forklift" }amount = 2150 # minor unitscurrency = "USD"from = "2026-01-01" # default: open; to as well
[[labor]] # labor entriesworkday = "2026-10-05"measure = "boxes"quantity = 10 # or a duration, "8h", for hourscategory = "pieces"values = { job = "pack" }segment = "p1" # the segment it belongs to, by its first punchreplaces = "l1" # and void = true to take it away# id (default l1, l2...), recorded (default: when the workday starts), by
[[approval_rule]] # what needs approvingsubject = "day" # day, period, category:<id>, entry, leave, # assignmentstages = ["supervisor", "payroll"]blocked_by_exceptions = true # default falseside = "bill" # default payorganizations = { 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 decisionsubject = "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 sidestage = "supervisor"decision = "approve" # approve, reject, disputerecorded = "2026-10-06 09:00"# by, comment; fingerprint: default, the subject's as it was when recorded
[[accrual_category]] # time off earned and usedid = "pto"uses = ["pto"] # the pay categories that draw it down
[[accrual_adjustment]] # a balance changed by handcategory = "pto"workday = "2026-10-06"amount = "8h" # or "-2h"
[[close]] # a pay period closed (or reopen = true)period = "2026-10-05" # its first dayrecorded = "2026-10-12 08:00"# by
[[clock]] # time passing: the clock moves on, step byto = "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 madeclosed = ["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 itid = "p1" # default p1, p2... in the order writtenrecorded = "2026-10-06 09:00" # default: when it happened
[[correction]] # one of add, move, void, retype, set_valuesid = "c1" # default c1, c2... in the order writtenrecorded = "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 weekworked = "9h"days = { "2026-10-05" = "9h" } # if given, a day not listed worked noneexceptions = [] # every exception is compared: none here; one is # { kind = "missing_out", at = "2026-10-06 08:00" }, # and detail = "..." matches its words toohours = "9.000" # the week's decimal hours (decimals = 3 in the # plant-7 layer), if givenlines = ["8.500", "0.500"] # each allocation's, in order, if givensegments = ["work 2026-10-05 08:00-17:00 job=pack"] # every segment of its workdays, effective timescontexts = ["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 sourcesallocations = ["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 paidstamps = ["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 orderquantities = ["2026-10-05 boxes 10 pieces assignment=A12 cost_center=4410 job=pack location=plant-7"] # every count and money line, in orderquantity_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 inday = "2026-10-07"side = "bill" # default payfirst = "2026-10-05" # its first and last day, if givenlast = "2026-10-18"worked = "9h" # and the rest, as aboveapprovals = ["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 onapproved = false # the timecard approved, as a whole or every # assignment of itaccruals = [] # 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 dayleave = ["v1 pending approval"] # the requests with a day in it, as they stand
[expect.export] # what an exporter writes of a pay perioduses = "standard/csv" # <package>/<name>params = { id_attribute = "payroll_id" }day = "2026-10-05" # a day of the periodside = "bill" # default payperson = "1001" # the person's id it is given (default person)file = """person,first,last,workday,category,hoursE1001,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, andlv1,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).
What it expects
Section titled “What it expects”[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.
| Key | Each entry, as written |
|---|---|
worked, paid | The 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. |
lines | Each allocation’s decimal hours, in the order paid: "0.33". |
segments | work 2026-10-05 08:00-12:00 job=pack: kind, effective span, values. |
contexts | work 2026-10-05 08:00 assignment=A12 [only_assignment]: each segment’s context, each value with its source. |
allocations | 2026-10-05 08:00-12:00 regular 4.00 assignment=A12: span (or untimed), category, hours, context. |
stamps | 2026-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. |
quantities | 2026-10-05 boxes 10 pieces job=pack: workday, measure, quantity, category, context. |
quantity_stamps | 2026-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" }. |
approvals | day:2026-10-05 approved (a period only). |
approved | Whether the timecard is approved, as a whole or every assignment of it (a period only). |
accruals, balances | 2026-10-05 pto earned 1h 20m; { pto = "1h 20m" } (a period only). |
calendar | 2026-10-05 08:00-16:30 shift, 2026-10-06 off leave, 2026-11-26 holiday thanks (a period only). |
file | What the exporter writes, whole (an export only). |
Time passing
Section titled “Time passing”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 catalogue
Section titled “The catalogue”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.