diff --git a/internal/atspi/adapter_capture.c b/internal/atspi/adapter_capture.c index f1dd73e..fe16c64 100644 --- a/internal/atspi/adapter_capture.c +++ b/internal/atspi/adapter_capture.c @@ -7,6 +7,49 @@ static gchar *cthulhu_capture_text(AtspiAccessible *source, gchar **beforeCaret, gint *startOffset); static void cthulhu_capture_document_metrics(AtspiAccessible *source, cthulhu_snapshot *snapshot); static gchar *cthulhu_table_cell_label(AtspiAccessible *source, guint depth, guint *remaining); +static gchar *cthulhu_label_text(AtspiAccessible *source); + +// Some toolkits expose an edit field's label only as a relation, leaving its +// accessible name empty. Follow direct targets only, with a shared query and +// output budget; never infer a label from neighbouring controls or field text. +static gchar *cthulhu_edit_field_label(AtspiAccessible *source) { + GArray *relations = atspi_accessible_get_relation_set(source, NULL); + if (relations == NULL) return NULL; + GString *label = g_string_new(""); + guint remaining = 16; + for (guint i = 0; i < MIN(relations->len, 32) && remaining > 0 && label->len < 4096; i++) { + AtspiRelation *relation = g_array_index(relations, AtspiRelation *, i); + if (atspi_relation_get_relation_type(relation) != ATSPI_RELATION_LABELLED_BY) continue; + gint count = atspi_relation_get_n_targets(relation); + for (gint j = 0; j < count && remaining > 0 && label->len < 4096; j++) { + remaining--; + AtspiAccessible *target = atspi_relation_get_target(relation, j); + if (target == NULL) continue; + AtspiRole role = atspi_accessible_get_role(target, NULL); + gchar *text = NULL; + if (role != ATSPI_ROLE_PASSWORD_TEXT) { + text = atspi_accessible_get_name(target, NULL); + if ((text == NULL || *text == '\0') && + (role == ATSPI_ROLE_LABEL || role == ATSPI_ROLE_STATIC)) { + g_free(text); + text = cthulhu_label_text(target); + } + } + if (text != NULL && *text != '\0') { + if (label->len != 0) g_string_append_c(label, ' '); + const gchar *end = NULL; + g_utf8_validate(text, MIN(strlen(text), 4096 - label->len), &end); + g_string_append_len(label, text, end - text); + } + g_free(text); + g_object_unref(target); + } + } + for (guint i = 0; i < relations->len; i++) + g_object_unref(g_array_index(relations, AtspiRelation *, i)); + g_array_unref(relations); + return g_string_free(label, FALSE); +} // Collect only the selected row. Walking an entire table on every arrow key // would block input in large application tables. @@ -387,6 +430,12 @@ cthulhu_snapshot cthulhu_capture_snapshot(AtspiAccessible *source, gboolean capt g_error_free(error); error = NULL; } + if (!snapshot.defunct && (snapshot.name == NULL || *snapshot.name == '\0') && + (g_strcmp0(snapshot.role, "text") == 0 || g_strcmp0(snapshot.role, "entry") == 0 || + g_strcmp0(snapshot.role, "password text") == 0)) { + g_free(snapshot.name); + snapshot.name = cthulhu_edit_field_label(source); + } if (!snapshot.defunct && (g_strcmp0(snapshot.role, "list") == 0 || g_strcmp0(snapshot.role, "list box") == 0)) { snapshot.childCount = atspi_accessible_get_child_count(source, &error); diff --git a/internal/atspi/edit_labels_native_test.go b/internal/atspi/edit_labels_native_test.go new file mode 100644 index 0000000..0f8d627 --- /dev/null +++ b/internal/atspi/edit_labels_native_test.go @@ -0,0 +1,91 @@ +// Copyright (c) 2026 Storm Dragon +// Authors: Storm Dragon, Angus Kola +// SPDX-License-Identifier: GPL-3.0-or-later + +package atspi_test + +import ( + "context" + "os" + "strings" + "testing" + "time" + + "git.stormux.org/storm/cthulhu/internal/atspi" + "git.stormux.org/storm/cthulhu/internal/presentation" +) + +// Missing LABELLED_BY capture must fail even when the toolkit leaves Name empty. +func TestNativeEditFieldLabels(t *testing.T) { + if os.Getenv("CTHULHU_NATIVE_EDIT_LABELS") != "1" { + t.Skip("requires isolated edit label fixture") + } + ctx, cancel := context.WithTimeout(context.Background(), 12*time.Second) + defer cancel() + adapter := atspi.New() + if err := adapter.Start(ctx); err != nil { + t.Fatal(err) + } + defer func() { + stopCtx, stopCancel := context.WithTimeout(context.Background(), 3*time.Second) + defer stopCancel() + if err := adapter.Stop(stopCtx); err != nil { + t.Error(err) + } + }() + tree, err := adapter.CaptureDesktop(ctx) + if err != nil { + t.Fatal(err) + } + root, err := tree.Root() + if err != nil { + t.Fatal(err) + } + fields := map[string]atspi.Snapshot{} + var walk func(atspi.ObjectReference) + walk = func(ref atspi.ObjectReference) { + snapshot, err := tree.Resolve(ref) + if err != nil { + t.Fatal(err) + } + if snapshot.Description != "" { + fields[snapshot.Description] = snapshot + } + child, ok, err := tree.FirstChild(ref) + if err != nil { + t.Fatal(err) + } + for ok { + walk(child) + child, ok, err = tree.NextSibling(child) + if err != nil { + t.Fatal(err) + } + } + } + walk(root) + for _, test := range []struct{ id, name string }{ + {"related", "Nickname"}, + {"multiple", "Account identifier"}, + {"named", "Explicit name"}, + {"unlabelled", ""}, + {"protected", "Password"}, + } { + t.Run(test.id, func(t *testing.T) { + snapshot, ok := fields[test.id] + if !ok { + t.Fatal("missing edit field") + } + if snapshot.Name != test.name { + t.Errorf("field label = %q, want %q", snapshot.Name, test.name) + } + spoken := presentation.FocusText(snapshot) + if test.name != "" && !strings.Contains(spoken, test.name) { + t.Errorf("speech %q omits label %q", spoken, test.name) + } + if test.id == "protected" && (snapshot.Text != "" || strings.Contains(spoken, "secret value")) { + t.Fatal("password contents exposed") + } + }) + } +} diff --git a/testdata/parity-ledger.csv b/testdata/parity-ledger.csv index e39bc1a..096c0a0 100644 --- a/testdata/parity-ledger.csv +++ b/testdata/parity-ledger.csv @@ -55,3 +55,4 @@ web-browse-braille-line,src/cthulhu/caret_navigation.py;src/cthulhu/scripts/web/ web-explicit-link-names,src/cthulhu/scripts/web/script_utilities.py:_treatObjectAsWhole,web,Read explicitly named links as whole objects without losing descendant badges or ordinary link navigation,Storm Dragon,internal/atspi internal/review internal/app,in-progress,"go test -race ./...; CTHULHU_NATIVE_BROWSER_TESTS=namedlinks,browser,live,keys python3 tests/native_browser.py",Private Brave/Xorg named-link and key checks passed,,Fixture speech verified; real Steam listening pending,Named-link browse braille uses the full accessible label; physical check pending,docs/testing/steam-browser.md; actual Steam explicit-name exposure and game-card acceptance remain live gates steam-notifications,src/cthulhu/scripts/apps/steamwebhelper/script.py;tests/test_steam_notification_regressions.py,web,Coalesce verified Steam background toasts and present once through speech braille and notification history,Storm Dragon,internal/webscripts internal/atspi internal/app,in-progress,go test -race ./...; python3 tests/native_webscripts.py,Private GTK/AT-SPI process matching and alert-root capture passed,,Event-loop background delivery and Chromium isolation passed; real Steam toast pending,Event-loop flash verified; physical Steam toast display pending,docs/testing/steam-browser.md; independent root and bus queues deliberately prevent unrelated toast timestamps from merging libreoffice-calc-basic,Orca src/orca/scripts/apps/soffice/script.py; Orca src/orca/ax_utilities_table.py; Orca src/orca/speech_generator.py,libreoffice,Present Calc cells and recover logical focus around editing and sheet changes,Storm Dragon,internal/app internal/atspi internal/presentation,in-progress,GOCACHE=/tmp/cthulhu-go-cache go test -race ./internal/atspi ./internal/app ./internal/presentation -count=1; /usr/bin/python3 tests/native_libreoffice.py,Private real LibreOffice Calc 26.2.6.3 on Xvfb and a private AT-SPI bus validates cell movement blanks F2 typing Escape Enter and sheet changes.,,Recorded speech assertions pass; audible and physical-input acceptance pending.,Recorded value and coordinate frames pass; physical Braille and editor routing acceptance pending.,Current Orca is the primary Office reference. Dedicated application policy follows verified process identity after foreground/security gates; native capture remains bounded. Formulas range announcements dynamic headers full-row reading and Writer workflows remain open. See LIBREOFFICE_SUPPORT.md. +edit-field-relation-labels,src/cthulhu/generator.py:_generateLabel;src/cthulhu/script_utilities.py:displayedLabel,speech,Announce relation-only labels for unnamed edit fields,,internal/atspi internal/presentation,implemented,CTHULHU_NATIVE_EDIT_LABELS=1 python3 tests/native_atspi.py; go test ./... -count=1; go vet ./...,Private GTK/Xvfb verifies single and multiple labels plus existing names and password exclusion. Read-only live irctest capture verifies all three settings labels. Maintainer confirmed installed-reader label speech on physical Xorg on 2026-10-20.,,Formatted speech includes each label. Maintainer confirmed the installed reader speaks irctest settings field labels on 2026-10-20.,Physical Braille check pending.,Direct LABELLED_BY targets supply an empty text or entry or password-field name. Queries and output are bounded; explicit names are preserved. Human diff review remains required before submission. diff --git a/tests/gtk_edit_labels.py b/tests/gtk_edit_labels.py new file mode 100644 index 0000000..147219f --- /dev/null +++ b/tests/gtk_edit_labels.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +"""Edit fields whose labels are exposed only through AT-SPI relations.""" +import gi + +gi.require_version("Gtk", "3.0") +gi.require_version("Atk", "1.0") +from gi.repository import Atk, Gtk + +window = Gtk.Window(title="Edit label probe") +window.connect("destroy", Gtk.main_quit) +box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8) +window.add(box) + + +def field(identifier, labels, name="", password=False): + entry = Gtk.Entry() + entry.set_text("secret value" if password else "sample value") + entry.set_visibility(not password) + accessible = entry.get_accessible() + accessible.set_name(name) + accessible.set_description(identifier) + for text in labels: + label = Gtk.Label(label=text) + box.pack_start(label, False, False, 0) + accessible.add_relationship(Atk.RelationType.LABELLED_BY, label.get_accessible()) + box.pack_start(entry, False, False, 0) + + +field("related", ["Nickname"]) +field("multiple", ["Account", "identifier"]) +field("named", ["Other label"], name="Explicit name") +field("unlabelled", []) +field("protected", ["Password"], password=True) +window.show_all() +Gtk.main() diff --git a/tests/native_atspi.py b/tests/native_atspi.py index 92edb93..7a0d06a 100644 --- a/tests/native_atspi.py +++ b/tests/native_atspi.py @@ -19,6 +19,9 @@ def wait_for(check, message, timeout=15): def run_inside(): + if os.environ.get("CTHULHU_NATIVE_EDIT_LABELS") == "1": + run_edit_label_probe() + return if os.environ.get("CTHULHU_MOUSE_REVIEW") == "1": run_probe("list") return @@ -38,6 +41,27 @@ def run_inside(): run_thunar_probe() +def run_edit_label_probe(): + fixture = subprocess.Popen([sys.executable, str(Path(__file__).with_name("gtk_edit_labels.py"))]) + try: + import pyatspi + + def find_window(): + return any(window.name == "Edit label probe" + for app in pyatspi.Registry.getDesktop(0) for window in app) + + wait_for(find_window, "edit label probe missing") + environment = dict(os.environ, GOCACHE="/tmp/cthulhu-go-cache", GOPROXY="off") + subprocess.run( + ["go", "test", "./internal/atspi", "-run", "^TestNativeEditFieldLabels$", + "-count=1", "-timeout=25s", "-v"], + cwd=Path(__file__).resolve().parents[1], env=environment, check=True, + ) + finally: + fixture.terminate() + fixture.wait(timeout=3) + + def run_thunar_probe(): with tempfile.TemporaryDirectory(prefix="cthulhu-thunar-") as temporary: home = Path(temporary)