oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire
2
3import (
4 "slices"
5 "strings"
6)
7
8// A probe's Detail is structured: never words, only codes the instance
9// words (copy.go, runner.probe_detail.<code>) and what a probe found
10// (names, counts, versions) as their parameters. Encoded as parts joined
11// by ";", each its code, then ":" and its parameters joined by ",".
12
13// ProbeDetailCodes is every detail code a runner sends, with how many
14// parameters it takes (each a %s in its wording).
15var ProbeDetailCodes = map[string]int{
16 ProbeDetailTurnBusy: 0, "probe_limit": 1, "not_run": 0, "f5_skipped": 0, "inputs_changed": 0,
17 "stale_runner": 0, "stale_settings": 0, "stale_cli": 0, "stale_xcode": 0, "stale_runtimes": 0, "future": 0, "expired": 0,
18 "launch_not_started": 1, "launch_unproven": 0, "script_not_run": 0, "other_command": 0, "records_foreign": 0,
19 "tree_unmade": 0, "not_prepared": 0, "no_loopback": 0, "script_unwritten": 0, "no_xcode": 0, "no_simulator": 0,
20 "xcode_unavailable": 1, "simulator_unavailable": 1, "fixture_uncopied": 0, "fixture_unprepared": 0, "no_sentinel": 0,
21 "allowed": 1, "not_shown_denied": 1, "not_collected": 1, "unix_only": 1, "reached_scratch": 1, "reached_tree": 1,
22 "not_set_up": 1, "incomplete": 1, "tree_unsearched": 0, "secrets_unreadable": 0, "not_all_denied": 0,
23 "loopback_hits": 1, "dns_control_failed": 0, "control_failed": 1,
24 "no_token_file": 0, "no_procargs_reader": 0, "ps_control_failed": 0, "procargs_not_sandboxed": 0, "procargs_incomplete": 0,
25 "process_list_unreadable": 0, "pipe_open": 1, "token_reached_scratch": 1, "token_reached_tree": 1, "token_reached": 1,
26 "not_shown_tried": 1, "env_unreadable": 0, "token_in_env": 0,
27 "control_read_missing": 0, "reached_model": 0, "not_shown_made": 1, "not_prescribed": 1, "unobserved": 1,
28 "write_denied_place": 0, "write_through_link": 1, "hard_linked": 1, "link_not_refused": 1,
29 "child_not_started": 0, "child_not_own_session": 0, "child_outlived": 0, "child_not_gone": 0,
30 "f1_denied": 0, "f2_denied": 1, "other_home_os": 0, "f3_denied": 0, "f4_passed": 0, "f5_denied": 0, "unix_home": 0,
31 "f6_denied": 1, "f7_denied": 0,
32 "xcode": 2, "ios_simulators": 1, "computer": 1, "srt_missing": 0, "user_temp_refused": 0, "all_denied": 1,
33 "end_unproven": 0, "srt_ran_xcode": 0, "srt_failed": 1, "srt_not_run": 0,
34 "p3_keychain_denied": 0, "p3_keychain_unshown": 0, "p3_keychain_unprobed": 0, "p5_parked": 0,
35 "homes_unchecked": 0, "homes_readable": 1, "homes_closed": 0, "agent_loaded": 0, "agent_not_loaded": 0,
36 "sleep_unknown": 0, "sleep_off": 0, "sleep_after": 1,
37 "test_not_started": 1, "group_gone": 1, "group_unproven": 0, "marked_left": 1, "still_running": 1,
38 "simulators_shut": 1, "tree_removed": 0, "tree_not_removable": 0,
39 "tool_missing": 1, "tool_version": 2, "node_old": 0, "srt_cannot_run": 0,
40}
41
42// maxDetailParam bounds one parameter.
43const maxDetailParam = 120
44
45// ProbeDetail is one part: code and its parameters, each kept to the
46// capability string rules and stripped of the separators.
47func ProbeDetail(code string, params ...string) string {
48 if len(params) == 0 {
49 return code
50 }
51 clean := make([]string, len(params))
52 for i, p := range params {
53 p = strings.Map(func(r rune) rune {
54 if strings.ContainsRune(";,:/\\~\n\r\t\x00=", r) {
55 return ' '
56 }
57 return r
58 }, p)
59 for len(p) > maxDetailParam {
60 p = p[:len(p)-1]
61 for len(p) > 0 && p[len(p)-1]&0xC0 == 0x80 {
62 p = p[:len(p)-1]
63 }
64 }
65 clean[i] = strings.TrimSpace(p)
66 }
67 return code + ":" + strings.Join(clean, ",")
68}
69
70// ProbeDetails joins parts (empty ones left out), keeping whole parts
71// while they fit MaxCapabilityString.
72func ProbeDetails(parts ...string) string {
73 var b strings.Builder
74 for _, p := range parts {
75 if p == "" {
76 continue
77 }
78 if n := b.Len() + len(p); b.Len() > 0 && n+1 > MaxCapabilityString || n > MaxCapabilityString {
79 break
80 }
81 if b.Len() > 0 {
82 b.WriteByte(';')
83 }
84 b.WriteString(p)
85 }
86 return b.String()
87}
88
89// ProbeDetailPart is one decoded part.
90type ProbeDetailPart struct {
91 Code string
92 Params []string
93}
94
95// ParseProbeDetail decodes d: only parts with a known code and its
96// number of parameters; ok when every part was one.
97func ParseProbeDetail(d string) (parts []ProbeDetailPart, ok bool) {
98 if d == "" {
99 return nil, true
100 }
101 ok = true
102 for _, raw := range strings.Split(d, ";") {
103 code, rest, has := strings.Cut(raw, ":")
104 var params []string
105 if has {
106 params = strings.Split(rest, ",")
107 }
108 if n, known := ProbeDetailCodes[code]; !known || n != len(params) || slices.ContainsFunc(params, func(p string) bool { return p == "" || p != strings.TrimSpace(p) }) {
109 ok = false
110 continue
111 }
112 parts = append(parts, ProbeDetailPart{Code: code, Params: params})
113 }
114 return parts, ok
115}
116