@shipload/sdk 1.0.0-next.53 → 1.0.0-next.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ import {describe, expect, test} from 'bun:test'
2
+ import {ServerContract, TaskType} from '../index-module'
3
+ import {hasPendingCapper, hasResolvable, isCapperTaskType} from './schedule'
4
+
5
+ const T0 = '2026-06-19T00:00:00'
6
+ const NOW = new Date('2026-06-19T00:01:00.000Z')
7
+
8
+ function task(over: Partial<{type: number; duration: number}>) {
9
+ return ServerContract.Types.task.from({
10
+ type: over.type ?? TaskType.TRAVEL,
11
+ duration: over.duration ?? 30,
12
+ cancelable: 0,
13
+ cargo: [],
14
+ couplings: [],
15
+ })
16
+ }
17
+
18
+ function entity(
19
+ tasks: ReturnType<typeof task>[],
20
+ holds: ServerContract.Types.hold[] = [],
21
+ startedISO = T0
22
+ ) {
23
+ return ServerContract.Types.entity_info.from({
24
+ type: 'ship',
25
+ id: 1,
26
+ owner: 'player.gm',
27
+ entity_name: 'Ship 1',
28
+ coordinates: {x: 0, y: 0, z: 0},
29
+ item_id: 1,
30
+ cargomass: 0,
31
+ cargo: [],
32
+ modules: [],
33
+ lanes: [{lane_key: 0, schedule: {started: startedISO, tasks}}],
34
+ gatherer_lanes: [],
35
+ crafter_lanes: [],
36
+ builder_lanes: [],
37
+ loader_lanes: [],
38
+ holds,
39
+ })
40
+ }
41
+
42
+ function hold(kind: number) {
43
+ return ServerContract.Types.hold.from({
44
+ id: 1,
45
+ kind,
46
+ counterpart: {entity_type: 'ship', entity_id: 2},
47
+ until: T0,
48
+ incoming_mass: 0,
49
+ })
50
+ }
51
+
52
+ describe('isCapperTaskType', () => {
53
+ test('UNDEPLOY, DEMOLISH, REFIT are cappers', () => {
54
+ expect(isCapperTaskType(TaskType.UNDEPLOY)).toBe(true)
55
+ expect(isCapperTaskType(TaskType.DEMOLISH)).toBe(true)
56
+ expect(isCapperTaskType(TaskType.REFIT)).toBe(true)
57
+ })
58
+
59
+ test('non-capper task types are not cappers', () => {
60
+ expect(isCapperTaskType(TaskType.TRAVEL)).toBe(false)
61
+ expect(isCapperTaskType(TaskType.LOAD)).toBe(false)
62
+ })
63
+ })
64
+
65
+ describe('hasPendingCapper', () => {
66
+ test('false with no schedule', () => {
67
+ expect(hasPendingCapper(entity([]))).toBe(false)
68
+ })
69
+
70
+ test('false with only non-capper tasks queued', () => {
71
+ expect(hasPendingCapper(entity([task({type: TaskType.TRAVEL})]))).toBe(false)
72
+ })
73
+
74
+ test('true when a REFIT task is queued anywhere in the lane', () => {
75
+ const e = entity([task({type: TaskType.TRAVEL}), task({type: TaskType.REFIT})])
76
+ expect(hasPendingCapper(e)).toBe(true)
77
+ })
78
+
79
+ test('true when a DEMOLISH task is queued', () => {
80
+ expect(hasPendingCapper(entity([task({type: TaskType.DEMOLISH})]))).toBe(true)
81
+ })
82
+ })
83
+
84
+ describe('hasResolvable — capper gating', () => {
85
+ test('a completed non-capper front is resolvable', () => {
86
+ const e = entity([task({type: TaskType.TRAVEL, duration: 30})])
87
+ expect(hasResolvable(e, NOW)).toBe(true)
88
+ })
89
+
90
+ test('a completed capper front with no holds is resolvable', () => {
91
+ const e = entity([task({type: TaskType.REFIT, duration: 30})])
92
+ expect(hasResolvable(e, NOW)).toBe(true)
93
+ })
94
+
95
+ test('a completed capper front with a live hold is gated', () => {
96
+ const e = entity([task({type: TaskType.REFIT, duration: 30})], [hold(2)])
97
+ expect(hasResolvable(e, NOW)).toBe(false)
98
+ })
99
+
100
+ test('a capper front clears once holds empty', () => {
101
+ const withHold = entity([task({type: TaskType.REFIT, duration: 30})], [hold(2)])
102
+ const cleared = entity([task({type: TaskType.REFIT, duration: 30})], [])
103
+ expect(hasResolvable(withHold, NOW)).toBe(false)
104
+ expect(hasResolvable(cleared, NOW)).toBe(true)
105
+ })
106
+
107
+ test('a live hold does not gate a non-capper front', () => {
108
+ const e = entity([task({type: TaskType.TRAVEL, duration: 30})], [hold(2)])
109
+ expect(hasResolvable(e, NOW)).toBe(true)
110
+ })
111
+
112
+ test('an in-progress front is not resolvable regardless of holds', () => {
113
+ const e = entity([task({type: TaskType.REFIT, duration: 3600})])
114
+ expect(hasResolvable(e, NOW)).toBe(false)
115
+ })
116
+ })
@@ -63,6 +63,24 @@ export function isIdle(entity: ScheduleData): boolean {
63
63
  return !hasSchedule(entity) && !hasHolds(entity)
64
64
  }
65
65
 
66
+ // Mirrors is_capper_task_type: demolish/undeploy/refit cap a plan — no further appends once queued.
67
+ export function isCapperTaskType(taskType: number): boolean {
68
+ return (
69
+ taskType === TaskType.UNDEPLOY ||
70
+ taskType === TaskType.DEMOLISH ||
71
+ taskType === TaskType.REFIT
72
+ )
73
+ }
74
+
75
+ export function hasPendingCapper(entity: ScheduleData): boolean {
76
+ for (const l of entity.lanes ?? []) {
77
+ for (const t of l.schedule.tasks) {
78
+ if (isCapperTaskType(t.type.toNumber())) return true
79
+ }
80
+ }
81
+ return false
82
+ }
83
+
66
84
  export function isEntityIdle(entity: ScheduleData, now: Date): boolean {
67
85
  if (hasHolds(entity)) return false
68
86
  const lanes = entity.lanes
@@ -121,10 +139,13 @@ export function scheduleComplete(entity: ScheduleData, now: Date): boolean {
121
139
  return remaining === 0
122
140
  }
123
141
 
124
- // Mirrors contract lane_front_complete: any lane whose front task is complete and non-reserved.
142
+ // Mirrors lane_front_complete && !capper_front_gated for own-entity holds (workshop/undeploy-target gates need cross-entity context this ScheduleData lacks).
125
143
  export function hasResolvable(entity: ScheduleData, now: Date): boolean {
126
144
  for (const l of entity.lanes ?? []) {
127
- if (core.laneTaskComplete(l.schedule, 0, now)) return true
145
+ if (!core.laneTaskComplete(l.schedule, 0, now)) continue
146
+ const front = l.schedule.tasks[0]
147
+ if (isCapperTaskType(front.type.toNumber()) && hasHolds(entity)) continue
148
+ return true
128
149
  }
129
150
  return false
130
151
  }
package/src/types.ts CHANGED
@@ -69,6 +69,13 @@ export enum TaskType {
69
69
  CHARGE = 16,
70
70
  UPGRADE = 17,
71
71
  SHUTTLE = 18,
72
+ REFIT = 19,
73
+ }
74
+
75
+ export enum RefitOp {
76
+ ADD = 0,
77
+ REMOVE = 1,
78
+ SWAP = 2,
72
79
  }
73
80
 
74
81
  export enum HoldKind {