gdharness 1.3.6 → 1.3.7

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.
@@ -152,7 +152,7 @@ static func not_of_kind(
152
152
  if not found.is_empty():
153
153
  told += ' The node at "%s" is %s, not %s.' % [node_path, with_article(found), with_article(kind)]
154
154
  if holders.is_empty():
155
- return told + " The scene holds no %s." % kind
155
+ return told + " The scene holds no %s; scene_node add with nodeType %s puts one in it." % [kind, kind]
156
156
  var quoted: PackedStringArray = []
157
157
  for holder: String in holders.slice(0, NAMED_CHILDREN):
158
158
  var _quoted: bool = quoted.append('"%s"' % holder)
@@ -170,17 +170,18 @@ func restart_editor(_args: Dictionary) -> Dictionary:
170
170
  )
171
171
  }
172
172
 
173
- var unsaved: Dictionary = _save_everything()
174
- if not unsaved.is_empty():
175
- return unsaved
173
+ var saving: Dictionary = _save_everything()
174
+ if not saving.has("saved"):
175
+ return saving
176
176
 
177
177
  # Deferred so this answer is on its way out before the editor goes.
178
178
  EditorInterface.restart_editor.call_deferred(true)
179
179
 
180
- return {"ok": true, "restarting": true, "saved": true}
180
+ return {"ok": true, "restarting": true, "saved": saving["saved"]}
181
181
 
182
182
 
183
- ## Saves every open scene, answering a refusal naming what is still unsaved, or {}.
183
+ ## Saves every open scene, answering a refusal naming what is still unsaved, or the scenes that had
184
+ ## changes and were saved, under `saved`.
184
185
  ##
185
186
  ## Read back rather than assumed: save_all_scenes answers nothing and passes over a scene that has
186
187
  ## never been saved, which has no path to go to, so an untitled scene was lost with the editor while
@@ -188,10 +189,11 @@ func restart_editor(_args: Dictionary) -> Dictionary:
188
189
  static func _save_everything() -> Dictionary:
189
190
  if EditorInterface.is_playing_scene():
190
191
  EditorInterface.stop_playing_scene()
192
+ var changed: PackedStringArray = EditorInterface.get_unsaved_scenes()
191
193
  EditorInterface.save_all_scenes()
192
194
  var left: PackedStringArray = EditorInterface.get_unsaved_scenes()
193
195
  if left.is_empty():
194
- return {}
196
+ return {"ok": true, "saved": changed}
195
197
  var named: Array[String] = []
196
198
  for scene: String in left:
197
199
  named.append(scene if not scene.is_empty() else "a scene that has never been saved")
@@ -221,14 +223,14 @@ static func _save_everything() -> Dictionary:
221
223
  ## Saved first, exactly as the restart above saves. The editor is going either way, and unsaved
222
224
  ## scenes are not this tool's to lose.
223
225
  func quit_editor(_args: Dictionary) -> Dictionary:
224
- var unsaved: Dictionary = _save_everything()
225
- if not unsaved.is_empty():
226
- return unsaved
226
+ var saving: Dictionary = _save_everything()
227
+ if not saving.has("saved"):
228
+ return saving
227
229
 
228
230
  # Deferred so this answer is on its way out before the editor goes.
229
231
  _leave.call_deferred()
230
232
 
231
- return {"ok": true, "quitting": true, "saved": true}
233
+ return {"ok": true, "quitting": true, "saved": saving["saved"]}
232
234
 
233
235
 
234
236
  ## What the editor said as it started each of its servers, and the debug adapter started again when
@@ -285,6 +285,17 @@ func modify_resource(args: Dictionary) -> Dictionary:
285
285
  var resource: Resource = ResourceLoader.load(res_path, "", ResourceLoader.CACHE_MODE_IGNORE)
286
286
  if resource == null:
287
287
  return {"ok": false, "error": "%s did not load as a resource." % res_path}
288
+ # A scene's own properties are its packed bundle, so a property named for a scene is one of its
289
+ # nodes', and "PackedScene has no property" left the caller looking for the tool that sets it.
290
+ if resource is PackedScene:
291
+ return {
292
+ "ok": false,
293
+ "error":
294
+ (
295
+ "%s is a scene: scene_node set changes one node's properties, the root's at nodePath \".\"."
296
+ % res_path
297
+ )
298
+ }
288
299
 
289
300
  var properties: Dictionary = _parse_properties_dict(args.get("properties", ""))
290
301
  var refused: String = _properties.write_all(resource, properties)
@@ -152,7 +152,7 @@ static func not_of_kind(
152
152
  if not found.is_empty():
153
153
  told += ' The node at "%s" is %s, not %s.' % [node_path, with_article(found), with_article(kind)]
154
154
  if holders.is_empty():
155
- return told + " The scene holds no %s." % kind
155
+ return told + " The scene holds no %s; scene_node add with nodeType %s puts one in it." % [kind, kind]
156
156
  var quoted: PackedStringArray = []
157
157
  for holder: String in holders.slice(0, NAMED_CHILDREN):
158
158
  var _quoted: bool = quoted.append('"%s"' % holder)
@@ -67,6 +67,13 @@ const SCRIPT_FLAGS: PackedStringArray = ["-s", "--script"]
67
67
  ## Serve a script run anyway, for somebody driving a `-s` script rather than a game.
68
68
  const SCRIPT_RUNS_SETTING: String = "gdharness/runtime/serve_script_runs"
69
69
 
70
+ ## The `res://` folders of scenes that are not the game, such as a bench: a run started on one is
71
+ ## not served. Kept in step with `QUIET_SCENES_SETTING` in src/setup.ts.
72
+ const QUIET_SCENES_SETTING: String = "gdharness/runtime/quiet_scenes_under"
73
+
74
+ ## What the engine takes a bare argument for as the scene to run, by its extension.
75
+ const SCENE_EXTENSIONS: PackedStringArray = ["tscn", "scn", "escn", "res", "tres"]
76
+
70
77
  ## The variable the editor addon puts into its own environment, which every game the editor plays
71
78
  ## inherits: it says which editor played this game, so a server can tell the editor's game from
72
79
  ## another of the same project that some other server started. Kept in step with
@@ -123,6 +130,9 @@ var _commands: Dictionary = {}
123
130
  var _loaded_version: String = _read_marker(VERSION_MARKER)
124
131
  var _loaded_digest: String = _read_marker(DIGEST_MARKER)
125
132
  var _profile_received: bool = false
133
+ ## Whether whatever started this game asked for a profile from its start, read before the variable
134
+ ## is taken out of the environment.
135
+ var _profiled_from_start: bool = false
126
136
  var _close_asked: bool = false
127
137
  var _close_frames: int = 0
128
138
  var _profiler_calibrated: bool = false
@@ -200,7 +210,9 @@ static func _window_dimension(axis: String, fallback: int) -> int:
200
210
  func _wait_for_the_profiler() -> void:
201
211
  if OS.get_environment(PROFILE_FROM_START).is_empty():
202
212
  return
203
- # Read once: a process this game starts inherits its environment and must not wait as well.
213
+ _profiled_from_start = true
214
+ # Read once: a process this game starts inherits its environment and must not wait as well, nor
215
+ # be served as a profiled run where a quiet scene would not be, as a bench's workers are.
204
216
  OS.unset_environment(PROFILE_FROM_START)
205
217
  if not EngineDebugger.is_active():
206
218
  return
@@ -446,6 +458,15 @@ func _start_server() -> void:
446
458
  _enabled = false
447
459
  return
448
460
 
461
+ # Nor a scene the project says is not the game. A bench is handed to the engine as a scene, the
462
+ # way a screen is, so it announced as the game for as long as it ran, and so did every worker
463
+ # engine it started, all under the project's own path. One started to be profiled from its start
464
+ # is served all the same, since only this addon hands the totals back as it quits.
465
+ var prefixes: Variant = ProjectSettings.get_setting(QUIET_SCENES_SETTING, PackedStringArray())
466
+ if not _profiled_from_start and not quiet_scene_in(OS.get_cmdline_args(), prefixes).is_empty():
467
+ _enabled = false
468
+ return
469
+
449
470
  _server = TCPServer.new()
450
471
  # listen() defaults bind_address to "*", which exposes the game to the whole network.
451
472
  var bind_address: String = str(ProjectSettings.get_setting(BIND_ADDRESS_SETTING, DEFAULT_BIND_ADDRESS))
@@ -474,6 +495,29 @@ func _start_server() -> void:
474
495
  print(listening)
475
496
 
476
497
 
498
+ ## The scene [param given] names for the engine to run, as a `res://` path, when it lies under one of
499
+ ## [param prefixes]; otherwise empty. The engine takes any bare argument ending in a scene's
500
+ ## extension for the scene, relative to the project or absolute, so each is read as it would.
501
+ static func quiet_scene_in(given: PackedStringArray, prefixes: Variant) -> String:
502
+ # A PackedStringArray as project.godot writes one, or an Array of strings as a hand might.
503
+ var folders: PackedStringArray = []
504
+ if prefixes is PackedStringArray:
505
+ folders = prefixes
506
+ elif prefixes is Array:
507
+ var listed: Array = prefixes
508
+ for prefix: Variant in listed:
509
+ if prefix is String:
510
+ var _kept: bool = folders.append(str(prefix))
511
+ for argument: String in given:
512
+ if argument.begins_with("-") or not SCENE_EXTENSIONS.has(argument.get_extension().to_lower()):
513
+ continue
514
+ var scene: String = ProjectSettings.localize_path(argument)
515
+ for folder: String in folders:
516
+ if not folder.is_empty() and scene.begins_with(folder):
517
+ return scene
518
+ return ""
519
+
520
+
477
521
  ## Whether the engine was told to run a script rather than the game.
478
522
  func _script_run() -> bool:
479
523
  var given: PackedStringArray = OS.get_cmdline_args()
@@ -10,6 +10,9 @@ const GdhScreen = preload("runtime_screen.gd")
10
10
  ## How far zoom enlarges at most. Sixteen makes a 3-pixel ring 48 pixels across, past any need to
11
11
  ## see it, and a 200-pixel region 3200, past the size anybody reads a picture at.
12
12
  const ZOOM_MOST: int = 16
13
+ ## Measured on a downstream game's 1280x720 frame: its interface text and pixel art read as they do
14
+ ## in the PNG, at a fifth of the PNG's size.
15
+ const JPEG_QUALITY: float = 0.8
13
16
 
14
17
  var _host: Node
15
18
  var _values: GdhValues
@@ -385,16 +388,28 @@ func _capture(viewport: Viewport, params: Dictionary, with_windows: bool = false
385
388
  % screenshot_path.get_base_dir()
386
389
  )
387
390
  )
388
- var save_error: Error = image.save_png(screenshot_path)
391
+ var answer: Dictionary = saved(image, screenshot_path)
392
+ answer.merge(described)
393
+ return answer
394
+
395
+
396
+ ## [param image] saved as a PNG at [param png_path], and as a JPEG beside it, which the server sends
397
+ ## instead when it is the smaller: a rendered frame is several times smaller as one, and every
398
+ ## picture sent stays in the caller's session. Not for a picture with transparency, which a JPEG
399
+ ## would flatten.
400
+ static func saved(image: Image, png_path: String) -> Dictionary:
401
+ var save_error: Error = image.save_png(png_path)
389
402
  if save_error != OK:
390
403
  return {"type": "error", "message": "Failed to save screenshot as PNG: " + str(save_error)}
391
-
392
404
  var answer: Dictionary = {
393
405
  "type": "screenshot_file",
394
406
  "format": "png",
395
407
  "width": image.get_width(),
396
408
  "height": image.get_height(),
397
- "path": screenshot_path
409
+ "path": png_path
398
410
  }
399
- answer.merge(described)
411
+ if image.detect_alpha() == Image.ALPHA_NONE:
412
+ var jpeg_path: String = png_path.get_basename() + ".jpg"
413
+ if image.save_jpg(jpeg_path, JPEG_QUALITY) == OK:
414
+ answer["jpegPath"] = jpeg_path
400
415
  return answer
@@ -9,7 +9,7 @@ extends RefCounted
9
9
  ## platform when the pointer crosses into the window, sets it. An injected event never crosses
10
10
  ## anything, and on gdharness's own desktop no pointer ever enters a window, so nothing was hovered.
11
11
  ## A BaseButton takes a mouse press only while hovered, so every click on a button in such a window
12
- ## was dropped while the press itself was routed to it. Reported from Tall Tales Inn, whose strip
12
+ ## was dropped while the press itself was routed to it. Reported from Game C, whose strip
13
13
  ## window holds its first-run question, and traced through Godot 4.7.2's source.
14
14
  ##
15
15
  ## What is supplied is what the engine does once the window has been entered: the control its own
@@ -257,7 +257,7 @@ static func can_read(holder: Variant, named: String) -> bool:
257
257
  ## counted as unclean for a read.
258
258
  ##
259
259
  ## A step written in double quotes is the key inside them, so a key holding a colon is one step:
260
- ## Alchemill keys its stock by namespaced ids, "stock:\"base:dew\"", and split at that colon the
260
+ ## Game D keys its stock by namespaced ids, "stock:\"base:dew\"", and split at that colon the
261
261
  ## step named a key "base" the map had never had.
262
262
  static func _key_in(map: Dictionary, named: String) -> Array:
263
263
  var word: String = key_written(named)
@@ -152,7 +152,7 @@ static func not_of_kind(
152
152
  if not found.is_empty():
153
153
  told += ' The node at "%s" is %s, not %s.' % [node_path, with_article(found), with_article(kind)]
154
154
  if holders.is_empty():
155
- return told + " The scene holds no %s." % kind
155
+ return told + " The scene holds no %s; scene_node add with nodeType %s puts one in it." % [kind, kind]
156
156
  var quoted: PackedStringArray = []
157
157
  for holder: String in holders.slice(0, NAMED_CHILDREN):
158
158
  var _quoted: bool = quoted.append('"%s"' % holder)
@@ -218,12 +218,14 @@ static func argument_after(args: PackedStringArray, flag: String) -> String:
218
218
 
219
219
 
220
220
  ## The errors each of [param suites] declares it expects, by suite path and then case name, read off
221
- ## the compiled suite's constants so a declaration is whatever the engine made of it. A suite
222
- ## declaring none is left out.
221
+ ## the compiled suite's constants so a declaration is whatever the engine made of it. A directory
222
+ ## listed is walked for its scripts, as gdUnit4 walks it for suites. Only a script whose source names
223
+ ## the constant is loaded: gdUnit4 stops on a suite that does not load only when its own load is the
224
+ ## one that fails, so a broken suite loaded here first let the rest of its directory run.
223
225
  static func expected_by_suite(suites: PackedStringArray) -> Dictionary:
224
226
  var expected: Dictionary = {}
225
- for path: String in suites:
226
- if not path.ends_with(".gd") or not ResourceLoader.exists(path):
227
+ for path: String in scripts_in(suites):
228
+ if not FileAccess.file_exists(path) or not FileAccess.get_file_as_string(path).contains(EXPECTED):
227
229
  continue
228
230
  var suite: Script = load(path)
229
231
  var declared: Variant = suite.get_script_constant_map().get(EXPECTED)
@@ -232,6 +234,26 @@ static func expected_by_suite(suites: PackedStringArray) -> Dictionary:
232
234
  return expected
233
235
 
234
236
 
237
+ ## The scripts [param paths] names: each script, and every script under each directory.
238
+ static func scripts_in(paths: PackedStringArray) -> PackedStringArray:
239
+ var found: PackedStringArray = []
240
+ var pending: PackedStringArray = []
241
+ for path: String in paths:
242
+ if path.ends_with(".gd"):
243
+ var _script: bool = found.append(path)
244
+ else:
245
+ var _directory: bool = pending.append(path.trim_suffix("/"))
246
+ while not pending.is_empty():
247
+ var directory: String = pending[pending.size() - 1]
248
+ pending.remove_at(pending.size() - 1)
249
+ for file: String in DirAccess.get_files_at(directory):
250
+ if file.ends_with(".gd"):
251
+ var _file: bool = found.append("%s/%s" % [directory, file])
252
+ for inner: String in DirAccess.get_directories_at(directory):
253
+ var _inner: bool = pending.append("%s/%s" % [directory, inner])
254
+ return found
255
+
256
+
235
257
  static func write_expected(path: String, suites: PackedStringArray) -> void:
236
258
  var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
237
259
  if file == null:
package/build/keeper.js CHANGED
@@ -703,6 +703,8 @@ function readMessage(body) {
703
703
  // src/game-debugger.ts
704
704
  var PAUSE_MS = 30000;
705
705
  var STEP_MS = 1e4;
706
+ var ADDON_STEP_MS = 5000;
707
+ var RUNTIME_ADDON = "res://addons/gdharness_runtime/";
706
708
  var READ_MS = 5000;
707
709
  var REPLIES = new Set([
708
710
  "debug_enter",
@@ -1085,9 +1087,29 @@ class GameDebugger {
1085
1087
  };
1086
1088
  }
1087
1089
  }
1090
+ let frames = await this.stack();
1091
+ const stepping = Date.now();
1092
+ while (frames !== null && this.held !== null && (frames[0]?.script.startsWith(RUNTIME_ADDON) ?? false) && Date.now() - stepping < ADDON_STEP_MS) {
1093
+ this.forget("debug_enter");
1094
+ this.send("step", [], this.held.thread);
1095
+ if (await this.next(GameDebugger.named("debug_enter"), STEP_MS) === null) {
1096
+ return {
1097
+ paused: false,
1098
+ note: `The game stopped in gdharness's runtime addon and was stepped on to reach its own script, and did not stop again within ${STEP_MS / 1000}s. It stops at the next line of script it runs; debug_state stack reads it then.`
1099
+ };
1100
+ }
1101
+ frames = await this.stack();
1102
+ }
1088
1103
  this.stoppedBy("Paused");
1089
- const frames = await this.stack();
1090
- return { paused: true, held: this.heldState(), stack: frames ?? [] };
1104
+ const stack = frames ?? [];
1105
+ return {
1106
+ paused: true,
1107
+ held: this.heldState(),
1108
+ stack,
1109
+ ...stack[0]?.script.startsWith(RUNTIME_ADDON) === true ? {
1110
+ note: `The game is held in gdharness's runtime addon, whose _process runs first in every frame: ${ADDON_STEP_MS / 1000}s of stepping reached no line of the game's own script, so it runs none from frame to frame. A breakpoint in the game's script stops it there.`
1111
+ } : {}
1112
+ };
1091
1113
  }
1092
1114
  stoppedBy(cause) {
1093
1115
  if (this.held !== null) {
@@ -1108,7 +1130,7 @@ class GameDebugger {
1108
1130
  return await exited === null ? { refused: `The game did not say it had gone on within ${READ_MS / 1000}s.` } : { continued: true };
1109
1131
  }
1110
1132
  this.forget("debug_enter");
1111
- this.send(how, [], held.thread);
1133
+ this.send(held.hasStack ? how : "step", [], held.thread);
1112
1134
  const entered = await this.next(GameDebugger.named("debug_enter"), STEP_MS);
1113
1135
  if (entered === null) {
1114
1136
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdharness",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "mcpName": "io.github.Aureliolo/gdharness",
5
5
  "description": "A harness for driving a Godot 4 project from an agent: editor addons, a runtime bridge into the running game, an MCP server in front of them, and a CLI that installs and diagnoses the Godot side.",
6
6
  "type": "module",