pinokiod 7.5.23 → 7.5.24

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.
@@ -575,20 +575,32 @@ class Api {
575
575
  // 1. if the scropt has 'on.stop', run it when stopping
576
576
  let requestPath = this.filePath(req.params.uri)
577
577
  this.clearResolvedAction(requestPath)
578
- let { cwd, script } = await this.resolveScript(requestPath)
579
- if (script.on) {
578
+ let cwd
579
+ let script
580
+ try {
581
+ const resolved = await this.resolveScript(requestPath)
582
+ cwd = resolved.cwd
583
+ script = resolved.script
584
+ } catch (e) {
585
+ if (!e || e.code !== "ENOENT") {
586
+ throw e
587
+ }
588
+ }
589
+ if (script && script.on) {
580
590
  if (script.on.stop) {
581
591
  await this.process(script.on.stop)
582
592
  }
583
593
  }
584
594
  // reset modules
585
- let modpath = this.resolvePath(cwd, req.params.uri)
586
- if (this.child_procs[modpath]) {
587
- let child_procs = Array.from(this.child_procs[modpath])
588
- for(let proc of child_procs) {
589
- delete this.mods[proc]
595
+ if (cwd) {
596
+ let modpath = this.resolvePath(cwd, req.params.uri)
597
+ if (this.child_procs[modpath]) {
598
+ let child_procs = Array.from(this.child_procs[modpath])
599
+ for(let proc of child_procs) {
600
+ delete this.mods[proc]
601
+ }
602
+ delete this.child_procs[modpath]
590
603
  }
591
- delete this.child_procs[modpath]
592
604
  }
593
605
 
594
606
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "7.5.23",
3
+ "version": "7.5.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1153,6 +1153,33 @@ test("api.stop stops the canonical script path when the visible run id is decora
1153
1153
  })
1154
1154
  })
1155
1155
 
1156
+ test("api.stop disconnects when the script was deleted before stop cleanup", async () => {
1157
+ await withApiStopFixture(async ({ api, launchPath, killedGroups, stopped, packets }) => {
1158
+ const decoratedId = `${launchPath}?cwd=undefined`
1159
+ api.resolveScript = async () => {
1160
+ const error = new Error("missing script")
1161
+ error.code = "ENOENT"
1162
+ throw error
1163
+ }
1164
+ api.running[launchPath] = true
1165
+ api.running[decoratedId] = true
1166
+ api.kernel.memory.local[launchPath] = { live: true }
1167
+ api.kernel.memory.local[decoratedId] = { live: true }
1168
+
1169
+ await api.stop({ params: { id: decoratedId } })
1170
+
1171
+ assert.equal(api.running[launchPath], undefined)
1172
+ assert.equal(api.running[decoratedId], undefined)
1173
+ assert.equal(api.kernel.memory.local[launchPath], undefined)
1174
+ assert.equal(api.kernel.memory.local[decoratedId], undefined)
1175
+ assert.ok(killedGroups.includes(launchPath), "canonical script group must be killed")
1176
+ assert.ok(killedGroups.includes(decoratedId), "visible run id group must remain stopped")
1177
+ assert.equal(stopped.length, 1)
1178
+ assert.equal(stopped[0].scriptPath, launchPath)
1179
+ assert.ok(packets.some((packet) => packet.type === "disconnect" && packet.id === decoratedId))
1180
+ })
1181
+ })
1182
+
1156
1183
  test("startup launch request does not block on its own startup status row", async () => {
1157
1184
  await withFixtureApps({
1158
1185
  target: {}