IF Commons GitHub

logical/state

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0005-machine-probe-state FR-001, 0005-machine-probe-state FR-002, 0005-machine-probe-state FR-003, 0005-machine-probe-state FR-004

The state of a machine as it is kept in Git: the keyed records of an observation and the status of each policy, with no time, no probe version and no counter that changes on its own, written as JSON with its keys in order so that a machine that did not change gives the same bytes and so no change in Git; and the structured difference of two states, which names each path added, removed or changed with both values, and each policy whose status moved.

import { diffStates, stateText, type MachineState } from "./state.ts";
const a: MachineState = { format: "machine-state/1", records: { os: { family: "ubuntu" } }, policies: { firewall: "fail" } };
stateText(a) === stateText(a); // true
diffStates(a, a).equal; // true

Source: commons/machine-probe/src/logical/state.ts

5 of 14 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

logical.MachineStatetypeno test imports it
type MachineState = {
  readonly format: "machine-state/1";
  readonly records: Readonly<Record<string, Json>>;
  /** The finding of each policy that does not depend on the time (a policy about how old the observation is is the journal's). */
  readonly policies: Readonly<Record<string, string>>;
};

The state of a machine: what was observed of it and how each policy judges it.

logical.stateOffunctionno test imports it
function stateOf(o: Observed): MachineState

The state of an observation.

logical.stateTextfunctionno test imports it
function stateText(s: MachineState): string

The text of a state: JSON with the keys in order, two spaces and a final line break, the same for the same state, so that a line that changed is a line Git shows.

logical.readStatefunctionno test imports it
function readState(text: string): Result<MachineState, string>

A state from its text, or why it is not one.

logical.PolicyMovetypeno test imports it
type PolicyMove = { readonly id: string; readonly from: string | null; readonly to: string | null };

A policy whose finding moved.

logical.StateDifftypeno test imports it
type StateDiff = { readonly equal: boolean; readonly records: Drift; readonly policies: readonly PolicyMove[] };

What differs between two states.

logical.diffStatesfunctionno test imports it
function diffStates(from: MachineState, to: MachineState): StateDiff

The difference between an earlier state and a later one: the keyed records as grc tells drift (added, removed and changed, naming the path and both values) and each policy that moved, in order of the policies' ids.

MachineStatetype
type MachineState = {
  readonly format: "machine-state/1";
  readonly records: Readonly<Record<string, Json>>;
  /** The finding of each policy that does not depend on the time (a policy about how old the observation is is the journal's). */
  readonly policies: Readonly<Record<string, string>>;
};

The state of a machine: what was observed of it and how each policy judges it.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

stateOffunction
function stateOf(o: Observed): MachineState

The state of an observation.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

stateTextfunction
function stateText(s: MachineState): string

The text of a state: JSON with the keys in order, two spaces and a final line break, the same for the same state, so that a line that changed is a line Git shows.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

readStatefunction
function readState(text: string): Result<MachineState, string>

A state from its text, or why it is not one.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

PolicyMovetypeno test imports it
type PolicyMove = { readonly id: string; readonly from: string | null; readonly to: string | null };

A policy whose finding moved.

StateDifftypeno test imports it
type StateDiff = { readonly equal: boolean; readonly records: Drift; readonly policies: readonly PolicyMove[] };

What differs between two states.

diffStatesfunction
function diffStates(from: MachineState, to: MachineState): StateDiff

The difference between an earlier state and a later one: the keyed records as grc tells drift (added, removed and changed, naming the path and both values) and each policy that moved, in order of the policies' ids.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.