Skip to content

KerbalAlarmClock test coverage and Alarm API completion#982

Merged
djungelorm merged 4 commits into
mainfrom
kac-tests-and-api
Jul 19, 2026
Merged

KerbalAlarmClock test coverage and Alarm API completion#982
djungelorm merged 4 commits into
mainfrom
kac-tests-and-api

Conversation

@djungelorm

Copy link
Copy Markdown
Member

The KerbalAlarmClock service had almost no test coverage (a single Available check that wasn't wired into the build) and its Alarm class had several gaps and defects, found by testing against a disassembled KerbalAlarmClock v3.14.0.0.

Enum fixes. Alarm.Type threw for science lab alarms and Alarm.Action threw for alarms whose action doesn't match one of the presets; the missing AlarmType.ScienceLab, AlarmAction.Custom and AlarmAction.Converted values are now mapped.

Alarm class. Adds Enabled, PlaySound, Triggered, SupportsRepeat and SupportsRepeatPeriod; fixes Remaining throwing an invalid cast (the wrapper unboxed the mod's KSPTimeSpan as a double); guards members against use after Remove; and makes alarm equality ID-based so the same alarm fetched twice compares equal. Triggered reflects the mod's internal triggered state as a pollable getter, so clients can watch for it with expression events/streams rather than a bespoke event RPC.

Tests. Adds a full create/round-trip/remove test suite covering every alarm property and alarm type, with a dedicated test craft, and wires the KerbalAlarmClock tests into //:test and //:lint so they run as part of the standard suite.

Testing. All 16 KerbalAlarmClock tests pass in-game against KerbalAlarmClock v3.14.0.0 on KSP 1.12.5.

@djungelorm djungelorm added this to the 0.6.0 milestone Jul 19, 2026
@djungelorm djungelorm added bug Something isn't working enhancement New feature or request service:kerbal-alarm-clock labels Jul 19, 2026
The mod's AlarmTypeEnum has a ScienceLab value and its AlarmActionEnum has
Custom and Converted values, none of which kRPC's AlarmType and AlarmAction
enums could represent. Because the enum conversions throw on unknown values,
reading Alarm.Type on a science lab alarm, or Alarm.Action on an alarm whose
action is a custom combination or was converted from an old alarm, raised an
error. Add the missing values to the enums, the conversion switches and the
vendored KACWrapper, and list them in the API documentation ordering.
Add the alarm fields the wrapper omitted: Enabled, PlaySound, Triggered
(reflecting the mod's internal field - streaming it or using it in an event
expression is how a client observes an alarm firing), and the
SupportsRepeat/SupportsRepeatPeriod flags that gate the repeat setters.

Also fix three defects found while testing the class: Remaining always
threw an invalid cast (the mod stores it as a KSPTimeSpan object, which
the wrapper unboxed as a double) and is now computed from the alarm time;
alarm equality compared wrapper object references, so the same alarm
fetched twice compared unequal; and Remove left the object usable, reading
stale data instead of failing - every member now throws a clean
"Alarm does not exist" error after removal, matching the SpaceCenter
alarm API.
Replace the three empty-state checks (which never created an alarm, so the
whole Alarm class was untested) with a create/round-trip/remove suite:
creation, list/name/type queries, attribute round-trips, repeat support
flags, action presets (and the ignored Custom/Converted writes), vessel and
transfer-body round-trips, alarm firing via Triggered, pinned enum member
sets, and access-after-remove errors. Adds a minimal craft for the vessel
round-trip.

The service had no test or lint rules and was absent from //:test and
//:lint; add the RemoteTech-style rules and the root entries.
@djungelorm
djungelorm merged commit 24687f1 into main Jul 19, 2026
29 checks passed
@djungelorm
djungelorm deleted the kac-tests-and-api branch July 19, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request service:kerbal-alarm-clock

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant