browser-broker 0.1.0

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.
Files changed (123) hide show
  1. package/.env.example +173 -0
  2. package/LICENSE +21 -0
  3. package/README.md +374 -0
  4. package/RELEASES.md +97 -0
  5. package/dist/package.json +58 -0
  6. package/dist/src/adapter/conformance/case.js +1 -0
  7. package/dist/src/adapter/conformance/cases.js +429 -0
  8. package/dist/src/adapter/conformance/discovery.js +156 -0
  9. package/dist/src/adapter/conformance/driver.js +1 -0
  10. package/dist/src/adapter/conformance/drivers.js +36 -0
  11. package/dist/src/adapter/conformance/run.js +224 -0
  12. package/dist/src/adapter/conformance/service-subject.js +165 -0
  13. package/dist/src/adapter/contract.js +24 -0
  14. package/dist/src/adapter/operations.js +114 -0
  15. package/dist/src/adapter/service-seam.js +1 -0
  16. package/dist/src/artifacts/names.js +229 -0
  17. package/dist/src/artifacts/store.js +174 -0
  18. package/dist/src/bin/broker-tool.js +63 -0
  19. package/dist/src/bin/broker.js +111 -0
  20. package/dist/src/browser/adoption.js +143 -0
  21. package/dist/src/browser/automation-probe.js +113 -0
  22. package/dist/src/browser/conformance/case.js +1 -0
  23. package/dist/src/browser/conformance/cases.js +192 -0
  24. package/dist/src/browser/conformance/run.js +102 -0
  25. package/dist/src/browser/conformance/subjects.js +19 -0
  26. package/dist/src/browser/discovery.js +226 -0
  27. package/dist/src/browser/driver.js +195 -0
  28. package/dist/src/browser/fake.js +585 -0
  29. package/dist/src/browser/launch.js +504 -0
  30. package/dist/src/browser/real.js +1425 -0
  31. package/dist/src/browser/setup.js +161 -0
  32. package/dist/src/capture/accounting.js +59 -0
  33. package/dist/src/capture/image.js +112 -0
  34. package/dist/src/capture/ladder.js +72 -0
  35. package/dist/src/capture/legibility.js +195 -0
  36. package/dist/src/capture/pipeline.js +153 -0
  37. package/dist/src/capture/tiers.js +166 -0
  38. package/dist/src/cli/adapter.js +233 -0
  39. package/dist/src/cli/commands.js +270 -0
  40. package/dist/src/cli/conformance-driver.js +119 -0
  41. package/dist/src/cli/diffs.js +122 -0
  42. package/dist/src/cli/image.js +274 -0
  43. package/dist/src/cli/index.js +895 -0
  44. package/dist/src/cli/login-command.js +401 -0
  45. package/dist/src/cli/operations-commands.js +186 -0
  46. package/dist/src/cli/reconcile-command.js +137 -0
  47. package/dist/src/cli/sign-in.js +134 -0
  48. package/dist/src/cli/telemetry.js +222 -0
  49. package/dist/src/config/environment.js +446 -0
  50. package/dist/src/diff/artifact-path.js +77 -0
  51. package/dist/src/diff/crops.js +102 -0
  52. package/dist/src/diff/geometry.js +122 -0
  53. package/dist/src/diff/image.js +132 -0
  54. package/dist/src/diff/mask.js +46 -0
  55. package/dist/src/diff/regions.js +263 -0
  56. package/dist/src/diff/settings.js +135 -0
  57. package/dist/src/doctor/checks.js +588 -0
  58. package/dist/src/doctor/report.js +152 -0
  59. package/dist/src/doctor/session.js +161 -0
  60. package/dist/src/errors.js +36 -0
  61. package/dist/src/feedback/read.js +119 -0
  62. package/dist/src/feedback/record.js +199 -0
  63. package/dist/src/operations/addresses.js +175 -0
  64. package/dist/src/operations/derive.js +109 -0
  65. package/dist/src/operations/ledger.js +194 -0
  66. package/dist/src/operations/status.js +197 -0
  67. package/dist/src/operations/telemetry.js +280 -0
  68. package/dist/src/report/document.js +419 -0
  69. package/dist/src/report/escape.js +68 -0
  70. package/dist/src/report/snapshot.js +97 -0
  71. package/dist/src/service/arbitration.js +537 -0
  72. package/dist/src/service/artifacts.js +85 -0
  73. package/dist/src/service/bridge.js +577 -0
  74. package/dist/src/service/broker.js +120 -0
  75. package/dist/src/service/browser-session.js +269 -0
  76. package/dist/src/service/capacity.js +62 -0
  77. package/dist/src/service/capture-seam.js +83 -0
  78. package/dist/src/service/capture-store.js +91 -0
  79. package/dist/src/service/comparison-store.js +101 -0
  80. package/dist/src/service/comparison.js +173 -0
  81. package/dist/src/service/events.js +93 -0
  82. package/dist/src/service/keys.js +68 -0
  83. package/dist/src/service/leases.js +147 -0
  84. package/dist/src/service/nudge.js +66 -0
  85. package/dist/src/service/operations/claim.js +692 -0
  86. package/dist/src/service/operations/give-back.js +131 -0
  87. package/dist/src/service/operations/pages.js +771 -0
  88. package/dist/src/service/operations/sign-in.js +915 -0
  89. package/dist/src/service/operations/status.js +62 -0
  90. package/dist/src/service/ownership.js +93 -0
  91. package/dist/src/service/pages.js +616 -0
  92. package/dist/src/service/pending-seeds.js +20 -0
  93. package/dist/src/service/queue.js +233 -0
  94. package/dist/src/service/reconcile.js +220 -0
  95. package/dist/src/service/refusals.js +262 -0
  96. package/dist/src/service/runtime.js +131 -0
  97. package/dist/src/service/signin-recovery.js +148 -0
  98. package/dist/src/service/storage-seed.js +239 -0
  99. package/dist/src/service/tabs.js +123 -0
  100. package/dist/src/store/budget.js +99 -0
  101. package/dist/src/store/location.js +42 -0
  102. package/dist/src/store/network-path.js +182 -0
  103. package/dist/src/store/network-volume.js +92 -0
  104. package/dist/src/store/open.js +226 -0
  105. package/dist/src/store/schema/step-001-initial.js +523 -0
  106. package/dist/src/store/schema/step-002-tab-budget.js +53 -0
  107. package/dist/src/store/schema/step-003-queue-order.js +110 -0
  108. package/dist/src/store/schema/step-004-tab-never-opened.js +100 -0
  109. package/dist/src/store/schema/step-005-storage-seed-event.js +90 -0
  110. package/dist/src/store/schema/step-006-signin-events.js +104 -0
  111. package/dist/src/store/schema/step-007-signin-without-process.js +92 -0
  112. package/dist/src/store/schema/step-008-signin-owner.js +76 -0
  113. package/dist/src/store/schema/step-009-named-browsers.js +138 -0
  114. package/dist/src/store/schema/step-010-signin-request.js +135 -0
  115. package/dist/src/store/schema/step.js +172 -0
  116. package/dist/src/store/schema/steps.js +58 -0
  117. package/dist/src/store/transaction.js +37 -0
  118. package/dist/src/tool/adapter.js +90 -0
  119. package/dist/src/tool/conformance-driver.js +184 -0
  120. package/dist/src/tool/protocol.js +310 -0
  121. package/dist/src/tool/session.js +351 -0
  122. package/dist/src/tool/tools.js +310 -0
  123. package/package.json +58 -0
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The numbers that decide a diff's output (`SCHEMA.md` §6.2, `MILESTONES.md`
3
+ * #43).
4
+ *
5
+ * Five values, every one an environment variable with a working default,
6
+ * because §1.10 is categorical: "every value this service reads is an
7
+ * environment variable with a working default", and there is no settings
8
+ * table to put them in.
9
+ *
10
+ * **Three of the five are copied onto every `comparisons` row** — the colour
11
+ * tolerance, the smallest area reported and the cap on regions — and §1.9 says
12
+ * why all three rather than one: "all three are mutable and all three
13
+ * determined the output — snapshotting one and referencing the others would be
14
+ * a record that is half-true". The other two shape the regions rather than
15
+ * decide what counts as changed, and the row's region list already carries
16
+ * their effect in the geometry it records.
17
+ */
18
+ /**
19
+ * The declarations, in the order §6.2 lists them.
20
+ *
21
+ * Written as data rather than as five reads so the walk test that asserts
22
+ * `.env.example` documents every declared variable has something to walk, and
23
+ * so a variable cannot be added to the code without appearing here.
24
+ */
25
+ export const DIFF_DECLARATIONS = [
26
+ {
27
+ key: 'BROKER_DIFF_COLOUR_TOLERANCE',
28
+ fallback: 0.1,
29
+ integer: false,
30
+ minimum: 0,
31
+ maximum: 1,
32
+ summary: 'how different two pixels must be before either counts as changed, from 0 to 1',
33
+ },
34
+ {
35
+ key: 'BROKER_DIFF_MINIMUM_REGION_AREA',
36
+ fallback: 64,
37
+ integer: true,
38
+ minimum: 0,
39
+ maximum: Number.MAX_SAFE_INTEGER,
40
+ summary: 'the smallest region reported, in square pixels of area',
41
+ },
42
+ {
43
+ key: 'BROKER_DIFF_MAXIMUM_REGIONS',
44
+ fallback: 12,
45
+ integer: true,
46
+ minimum: 1,
47
+ maximum: Number.MAX_SAFE_INTEGER,
48
+ summary: 'how many regions come back before the result is truncated',
49
+ },
50
+ {
51
+ key: 'BROKER_DIFF_REGION_MERGE_DISTANCE',
52
+ fallback: 8,
53
+ integer: true,
54
+ minimum: 0,
55
+ maximum: Number.MAX_SAFE_INTEGER,
56
+ summary: 'how far apart two changed areas stay separate regions, in pixels',
57
+ },
58
+ {
59
+ key: 'BROKER_DIFF_CROP_PADDING',
60
+ fallback: 16,
61
+ integer: true,
62
+ minimum: 0,
63
+ maximum: Number.MAX_SAFE_INTEGER,
64
+ summary: 'context around a crop, in pixels',
65
+ },
66
+ ];
67
+ /** Every variable this feature declares. The walk test reads this. */
68
+ export const DECLARED_DIFF_VARIABLES = DIFF_DECLARATIONS.map((d) => d.key);
69
+ /** The defaults, as one snapshot, for anything that needs them without an environment. */
70
+ export const DEFAULT_DIFF_SETTINGS = {
71
+ colourTolerance: 0.1,
72
+ minimumRegionArea: 64,
73
+ maximumRegions: 12,
74
+ regionMergeDistance: 8,
75
+ cropPadding: 16,
76
+ };
77
+ /**
78
+ * Raised when a variable is set to something that is not the number it
79
+ * declares.
80
+ *
81
+ * A plain `Error` rather than one of the service's refusal classes, and the
82
+ * reason is a dependency direction worth keeping: this module is arithmetic
83
+ * over five numbers and nothing else in it reaches the service layer. The
84
+ * caller that reads settings is what decides whether a bad value refuses the
85
+ * spawn or refuses the call, and it has both classes available.
86
+ */
87
+ export class DiffSettingError extends Error {
88
+ key;
89
+ constructor(key, message) {
90
+ super(message);
91
+ this.name = 'DiffSettingError';
92
+ this.key = key;
93
+ }
94
+ }
95
+ function readNumber(declaration, raw) {
96
+ if (raw === undefined) {
97
+ return declaration.fallback;
98
+ }
99
+ // Set-and-blank is a value somebody wrote and meant something by, and no
100
+ // number is the one thing it cannot mean. Falling back silently would run a
101
+ // configuration nobody chose.
102
+ if (raw.trim() === '') {
103
+ throw new DiffSettingError(declaration.key, `${declaration.key} is set but empty. Expected ${declaration.summary}; unset it to use ${String(declaration.fallback)}.`);
104
+ }
105
+ const value = Number(raw);
106
+ if (!Number.isFinite(value)) {
107
+ throw new DiffSettingError(declaration.key, `${declaration.key} is set to ${JSON.stringify(raw)}, which is not a number. Expected ${declaration.summary}.`);
108
+ }
109
+ if (declaration.integer && !Number.isInteger(value)) {
110
+ throw new DiffSettingError(declaration.key, `${declaration.key} is set to ${JSON.stringify(raw)}, which is not a whole number. Expected ${declaration.summary}.`);
111
+ }
112
+ if (value < declaration.minimum || value > declaration.maximum) {
113
+ throw new DiffSettingError(declaration.key, `${declaration.key} is set to ${JSON.stringify(raw)}, which is outside ${String(declaration.minimum)} to ${String(declaration.maximum)}. Expected ${declaration.summary}.`);
114
+ }
115
+ return value;
116
+ }
117
+ /**
118
+ * Take the snapshot, from the environment §6.3 already read once per process.
119
+ */
120
+ export function readDiffSettings(env = process.env) {
121
+ const read = (key) => {
122
+ const declaration = DIFF_DECLARATIONS.find((d) => d.key === key);
123
+ if (declaration === undefined) {
124
+ throw new Error(`${key} is read but not declared`);
125
+ }
126
+ return readNumber(declaration, env[key]);
127
+ };
128
+ return {
129
+ colourTolerance: read('BROKER_DIFF_COLOUR_TOLERANCE'),
130
+ minimumRegionArea: read('BROKER_DIFF_MINIMUM_REGION_AREA'),
131
+ maximumRegions: read('BROKER_DIFF_MAXIMUM_REGIONS'),
132
+ regionMergeDistance: read('BROKER_DIFF_REGION_MERGE_DISTANCE'),
133
+ cropPadding: read('BROKER_DIFF_CROP_PADDING'),
134
+ };
135
+ }