Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions packages/effect-daemon-conformance/src/TraceComparison.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ const ComparisonTypeId: unique symbol = Symbol.for('@systemfsoftware/effect-daem
type ComparisonTypeId = typeof ComparisonTypeId

/** The candidate reproduced the reference within its declaration. */
export class TracesConform extends Schema.TaggedClass<TracesConform>()('TracesConform', {
scenario: Schema.String,
medium: Schema.String,
compared: Schema.Int,
}) {
export class TracesConform
extends Schema.TaggedClass<TracesConform, { readonly brand: unique symbol }>()('TracesConform', {
scenario: Schema.String,
medium: Schema.String,
compared: Schema.Int,
})
{
readonly [ComparisonTypeId] = ComparisonTypeId
}

/** The candidate first diverged from the reference at `index`. */
export class TracesDiverge extends Schema.TaggedClass<TracesDiverge>()('TracesDiverge', {
scenario: Schema.String,
medium: Schema.String,
index: Schema.Int,
reference: Schema.String,
candidate: Schema.String,
}) {
export class TracesDiverge
extends Schema.TaggedClass<TracesDiverge, { readonly brand: unique symbol }>()('TracesDiverge', {
scenario: Schema.String,
medium: Schema.String,
index: Schema.Int,
reference: Schema.String,
candidate: Schema.String,
})
{
readonly [ComparisonTypeId] = ComparisonTypeId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import type { ObservedStep } from './Trace.schema.js'
import { ObservedStep as ObservedStepSchema } from './Trace.schema.js'
import { TraceComparison, TracesConform, TracesDiverge } from './TraceComparison.schema.js'

export class CompareTraces extends Schema.TaggedClass<CompareTraces>()('CompareTraces', {
scenario: Schema.String,
medium: Schema.String,
reference: Schema.Array(ObservedStepSchema),
candidate: Schema.Array(ObservedStepSchema),
}) {
export class CompareTraces
extends Schema.TaggedClass<CompareTraces, { readonly brand: unique symbol }>()('CompareTraces', {
scenario: Schema.String,
medium: Schema.String,
reference: Schema.Array(ObservedStepSchema),
candidate: Schema.Array(ObservedStepSchema),
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
26 changes: 16 additions & 10 deletions packages/effect-daemon-conformance/src/project-trace.workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ const ProjectionTypeId: unique symbol = Symbol.for('@systemfsoftware/effect-daem
type ProjectionTypeId = typeof ProjectionTypeId

/** A declaration demanded no loss: the projected steps equal the trace's own. */
export class TracePreserved extends Schema.TaggedClass<TracePreserved>()('TracePreserved', {
steps: Schema.Array(ObservedStepSchema),
}) {
export class TracePreserved
extends Schema.TaggedClass<TracePreserved, { readonly brand: unique symbol }>()('TracePreserved', {
steps: Schema.Array(ObservedStepSchema),
})
{
readonly [ProjectionTypeId] = ProjectionTypeId
}

/** A declaration erased something: a report was coarsened or a stop order relaxed. */
export class TraceReduced extends Schema.TaggedClass<TraceReduced>()('TraceReduced', {
steps: Schema.Array(ObservedStepSchema),
}) {
export class TraceReduced
extends Schema.TaggedClass<TraceReduced, { readonly brand: unique symbol }>()('TraceReduced', {
steps: Schema.Array(ObservedStepSchema),
})
{
readonly [ProjectionTypeId] = ProjectionTypeId
}

export const TraceProjection = Schema.Union([TracePreserved, TraceReduced])
export type TraceProjection = typeof TraceProjection.Type

export class ProjectTrace extends Schema.TaggedClass<ProjectTrace>()('ProjectTrace', {
trace: ConformanceTrace,
declaration: Supervisor.Medium.MediumDeclaration,
}) {
export class ProjectTrace
extends Schema.TaggedClass<ProjectTrace, { readonly brand: unique symbol }>()('ProjectTrace', {
trace: ConformanceTrace,
declaration: Supervisor.Medium.MediumDeclaration,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ const KillSignalDecisionTypeId: unique symbol = Symbol.for(
)
type KillSignalDecisionTypeId = typeof KillSignalDecisionTypeId

export class BrutalKill extends Schema.TaggedClass<BrutalKill>()('BrutalKill', {}) {
export class BrutalKill extends Schema.TaggedClass<BrutalKill, { readonly brand: unique symbol }>()('BrutalKill', {}) {
readonly [KillSignalDecisionTypeId] = KillSignalDecisionTypeId
}

export class GracefulKill extends Schema.TaggedClass<GracefulKill>()('GracefulKill', {
forceKillAfterMillis: Schema.Int,
}) {
export class GracefulKill
extends Schema.TaggedClass<GracefulKill, { readonly brand: unique symbol }>()('GracefulKill', {
forceKillAfterMillis: Schema.Int,
})
{
readonly [KillSignalDecisionTypeId] = KillSignalDecisionTypeId
}

export class PatientKill extends Schema.TaggedClass<PatientKill>()('PatientKill', {}) {
export class PatientKill
extends Schema.TaggedClass<PatientKill, { readonly brand: unique symbol }>()('PatientKill', {})
{
readonly [KillSignalDecisionTypeId] = KillSignalDecisionTypeId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ const ProcessExitDecisionTypeId: unique symbol = Symbol.for(
)
type ProcessExitDecisionTypeId = typeof ProcessExitDecisionTypeId

export class ProcessExitNormal extends Schema.TaggedClass<ProcessExitNormal>()('ProcessExitNormal', {}) {
export class ProcessExitNormal
extends Schema.TaggedClass<ProcessExitNormal, { readonly brand: unique symbol }>()('ProcessExitNormal', {})
{
readonly [ProcessExitDecisionTypeId] = ProcessExitDecisionTypeId
}

export class ProcessExitAbnormal extends Schema.TaggedClass<ProcessExitAbnormal>()('ProcessExitAbnormal', {
code: Schema.Int,
signal: Schema.String,
}) {
export class ProcessExitAbnormal
extends Schema.TaggedClass<ProcessExitAbnormal, { readonly brand: unique symbol }>()('ProcessExitAbnormal', {
code: Schema.Int,
signal: Schema.String,
})
{
readonly [ProcessExitDecisionTypeId] = ProcessExitDecisionTypeId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import * as Result from 'effect/Result'
import { ProcessExit } from './ProcessExit.schema.js'
import { ProcessExitAbnormal, ProcessExitDecision, ProcessExitNormal } from './ProcessExitDecision.schema.js'

export class ClassifyProcessExit extends Schema.TaggedClass<ClassifyProcessExit>()('ClassifyProcessExit', {
exit: ProcessExit,
}) {
export class ClassifyProcessExit
extends Schema.TaggedClass<ClassifyProcessExit, { readonly brand: unique symbol }>()('ClassifyProcessExit', {
exit: ProcessExit,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { Match, Schema } from 'effect'
import * as Result from 'effect/Result'
import { BrutalKill, GracefulKill, KillSignalDecision, PatientKill } from './KillSignalDecision.schema.js'

export class SelectKillSignals extends Schema.TaggedClass<SelectKillSignals>()('SelectKillSignals', {
mode: Supervisor.Medium.ShutdownMode,
}) {
export class SelectKillSignals
extends Schema.TaggedClass<SelectKillSignals, { readonly brand: unique symbol }>()('SelectKillSignals', {
mode: Supervisor.Medium.ShutdownMode,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ const PeerCloseTypeId: unique symbol = Symbol.for(
)
type PeerCloseTypeId = typeof PeerCloseTypeId

export class PeerClosedCleanly extends Schema.TaggedClass<PeerClosedCleanly>()('PeerClosedCleanly', {}) {
export class PeerClosedCleanly
extends Schema.TaggedClass<PeerClosedCleanly, { readonly brand: unique symbol }>()('PeerClosedCleanly', {})
{
readonly [PeerCloseTypeId] = PeerCloseTypeId
}

export class PeerClosedAbnormally extends Schema.TaggedClass<PeerClosedAbnormally>()('PeerClosedAbnormally', {}) {
export class PeerClosedAbnormally
extends Schema.TaggedClass<PeerClosedAbnormally, { readonly brand: unique symbol }>()('PeerClosedAbnormally', {})
{
readonly [PeerCloseTypeId] = PeerCloseTypeId
}

export const PeerCloseDecision = Schema.Union([PeerClosedCleanly, PeerClosedAbnormally])
export type PeerCloseDecision = typeof PeerCloseDecision.Type

export class ClassifyPeerClose extends Schema.TaggedClass<ClassifyPeerClose>()('ClassifyPeerClose', {
code: Schema.Int,
}) {
export class ClassifyPeerClose
extends Schema.TaggedClass<ClassifyPeerClose, { readonly brand: unique symbol }>()('ClassifyPeerClose', {
code: Schema.Int,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ const ChildExitTypeId: unique symbol = Symbol.for(
type ChildExitTypeId = typeof ChildExitTypeId

/** The child ended on its own success. */
export class NormalExit extends Schema.TaggedClass<NormalExit>()('Normal', {}) {
export class NormalExit extends Schema.TaggedClass<NormalExit, { readonly brand: unique symbol }>()('Normal', {}) {
readonly [ChildExitTypeId] = ChildExitTypeId
}

/** The child was interrupted — an owned shutdown, or one it raised itself. */
export class ShutdownExit extends Schema.TaggedClass<ShutdownExit>()('Shutdown', {}) {
export class ShutdownExit
extends Schema.TaggedClass<ShutdownExit, { readonly brand: unique symbol }>()('Shutdown', {})
{
readonly [ChildExitTypeId] = ChildExitTypeId
}

/** The child failed with something other than an interruption. */
export class AbnormalExit extends Schema.TaggedClass<AbnormalExit>()('Abnormal', {}) {
export class AbnormalExit
extends Schema.TaggedClass<AbnormalExit, { readonly brand: unique symbol }>()('Abnormal', {})
{
readonly [ChildExitTypeId] = ChildExitTypeId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { TerminationReason } from '../kernel/TerminationReport.schema.js'

const firstLine = (text: string): string => text.split('\n')[0] ?? ''

export class SupervisorTerminated extends Schema.TaggedError<SupervisorTerminated>()('SupervisorTerminated', {
name: Schema.String,
reason: TerminationReason,
cause: Schema.Cause(Schema.Unknown, Schema.Unknown),
}) {
export class SupervisorTerminated
extends Schema.TaggedError<SupervisorTerminated, { readonly brand: unique symbol }>()('SupervisorTerminated', {
supervisor: Schema.String,
reason: TerminationReason,
cause: Schema.Cause(Schema.Unknown, Schema.Unknown),
})
{
override get message(): string {
return `Supervisor "${this.name}" terminated (${this.reason._tag}): ${firstLine(Cause.pretty(this.cause))}`
return `Supervisor "${this.supervisor}" terminated (${this.reason._tag}): ${firstLine(Cause.pretty(this.cause))}`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Cause, Exit, Match, Schema } from 'effect'
import * as Result from 'effect/Result'
import { AbnormalExit, ChildExitDecision, NormalExit, ShutdownExit } from './ChildExitDecision.schema.js'

export class ClassifyChildExit extends Schema.TaggedClass<ClassifyChildExit>()('ClassifyChildExit', {
stopping: Schema.Boolean,
exit: Schema.Exit(Schema.Void, Schema.Unknown, Schema.Unknown),
}) {
export class ClassifyChildExit
extends Schema.TaggedClass<ClassifyChildExit, { readonly brand: unique symbol }>()('ClassifyChildExit', {
stopping: Schema.Boolean,
exit: Schema.Exit(Schema.Void, Schema.Unknown, Schema.Unknown),
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ const executeTerminate = (
Effect.asVoid(
Deferred.fail(
terminatedLatchOf(acquired.handle),
new SupervisorTerminated({ name: acquired.handle.name, reason: command.reason, cause }),
new SupervisorTerminated({ supervisor: acquired.handle.name, reason: command.reason, cause }),
),
),
))),
Expand Down
24 changes: 15 additions & 9 deletions packages/effect-daemon-spec/src/kernel/SupervisorState.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,39 @@ export type SupervisorCore = typeof SupervisorCore.Type
export const ChildStart = Schema.Struct({ childId: ChildId, generation: Generation })
export type ChildStart = typeof ChildStart.Type

export class Running extends Schema.TaggedClass<Running>()('Running', { core: SupervisorCore }) {
export class Running
extends Schema.TaggedClass<Running, { readonly brand: unique symbol }>()('Running', { core: SupervisorCore })
{
readonly [StateTypeId] = StateTypeId
}

export class Restarting extends Schema.TaggedClass<Restarting>()('Restarting', {
export class Restarting extends Schema.TaggedClass<Restarting, { readonly brand: unique symbol }>()('Restarting', {
core: SupervisorCore,
pending: Schema.Array(ChildStart),
}) {
readonly [StateTypeId] = StateTypeId
}

export class CoolingDown extends Schema.TaggedClass<CoolingDown>()('CoolingDown', {
export class CoolingDown extends Schema.TaggedClass<CoolingDown, { readonly brand: unique symbol }>()('CoolingDown', {
core: SupervisorCore,
millis: PositiveMillis,
}) {
readonly [StateTypeId] = StateTypeId
}

export class ShuttingDown extends Schema.TaggedClass<ShuttingDown>()('ShuttingDown', {
core: SupervisorCore,
reason: TerminationReason,
exit: SupervisorExit,
}) {
export class ShuttingDown
extends Schema.TaggedClass<ShuttingDown, { readonly brand: unique symbol }>()('ShuttingDown', {
core: SupervisorCore,
reason: TerminationReason,
exit: SupervisorExit,
})
{
readonly [StateTypeId] = StateTypeId
}

export class Terminated extends Schema.TaggedClass<Terminated>()('Terminated', { reason: TerminationReason }) {
export class Terminated extends Schema.TaggedClass<Terminated, { readonly brand: unique symbol }>()('Terminated', {
reason: TerminationReason,
}) {
readonly [StateTypeId] = StateTypeId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Result, Schema } from 'effect'
import { SupervisionDecision } from './interpret-supervision-event.workflow.js'
import { evolved, SupervisorState } from './SupervisorState.schema.js'

export class SupervisionEvolution extends Schema.TaggedClass<SupervisionEvolution>()('SupervisionEvolution', {
state: SupervisorState,
decision: SupervisionDecision,
}) {
export class SupervisionEvolution
extends Schema.TaggedClass<SupervisionEvolution, { readonly brand: unique symbol }>()('SupervisionEvolution', {
state: SupervisorState,
decision: SupervisionDecision,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}

Expand Down
Loading
Loading