sessionyard 0.7.0__py3-none-any.whl
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.
- agent_chat/001_core.sql +172 -0
- agent_chat/002_coordination.sql +63 -0
- agent_chat/003_harness_admission.sql +10 -0
- agent_chat/004_session_titles.sql +3 -0
- agent_chat/005_viewer.sql +9 -0
- agent_chat/006_quotas.sql +6 -0
- agent_chat/007_sender_receipts.sql +20 -0
- agent_chat/008_direct_threads.sql +49 -0
- agent_chat/009_pm_mark.sql +23 -0
- agent_chat/010_quota_backfill.sql +12 -0
- agent_chat/011_roles_and_work.sql +31 -0
- agent_chat/__init__.py +1 -0
- agent_chat/adapter.py +414 -0
- agent_chat/admin.py +524 -0
- agent_chat/api.py +641 -0
- agent_chat/auth.py +226 -0
- agent_chat/browser.py +118 -0
- agent_chat/browser_verify.py +487 -0
- agent_chat/browser_verify_artifacts.py +280 -0
- agent_chat/browser_verify_checks.py +236 -0
- agent_chat/browser_verify_run.py +523 -0
- agent_chat/cli.py +532 -0
- agent_chat/client.py +272 -0
- agent_chat/deliveries.py +555 -0
- agent_chat/events.py +48 -0
- agent_chat/feed.py +193 -0
- agent_chat/http_boundary.py +154 -0
- agent_chat/instance_client.py +349 -0
- agent_chat/instance_file.py +207 -0
- agent_chat/instance_worker.py +326 -0
- agent_chat/mcp/__init__.py +5 -0
- agent_chat/mcp/__main__.py +39 -0
- agent_chat/mcp/app.py +183 -0
- agent_chat/mcp/auth.py +67 -0
- agent_chat/mcp/config.py +55 -0
- agent_chat/mcp/tools.py +295 -0
- agent_chat/metrics.py +60 -0
- agent_chat/models.py +430 -0
- agent_chat/openapi.py +322 -0
- agent_chat/producer.py +208 -0
- agent_chat/protocol.py +71 -0
- agent_chat/publication.py +252 -0
- agent_chat/receipts.py +225 -0
- agent_chat/retention.py +154 -0
- agent_chat/roles.py +153 -0
- agent_chat/rooms.py +179 -0
- agent_chat/sessions.py +340 -0
- agent_chat/skills/agent-chat/SKILL.md +64 -0
- agent_chat/state.py +144 -0
- agent_chat/storage.py +110 -0
- agent_chat/threads.py +50 -0
- agent_chat/web/Manrope-OFL.txt +93 -0
- agent_chat/web/Manrope-Variable.ttf +0 -0
- agent_chat/web/chat.css +936 -0
- agent_chat/web/chat.js +1922 -0
- agent_chat/web/i18n.js +340 -0
- agent_chat/web/index.html +264 -0
- sessionyard-0.7.0.dist-info/METADATA +314 -0
- sessionyard-0.7.0.dist-info/RECORD +62 -0
- sessionyard-0.7.0.dist-info/WHEEL +4 -0
- sessionyard-0.7.0.dist-info/entry_points.txt +3 -0
- sessionyard-0.7.0.dist-info/licenses/LICENSE +661 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""Opt-in private PNGs under a binding-owned retention contract; no expiry provisioning."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import stat
|
|
7
|
+
import struct
|
|
8
|
+
import zlib
|
|
9
|
+
from typing import Any
|
|
10
|
+
from uuid import uuid4
|
|
11
|
+
|
|
12
|
+
from .browser_verify import ArtifactPolicy, Request, Stop, private_directory
|
|
13
|
+
|
|
14
|
+
MAX_IMAGES = 4
|
|
15
|
+
MAX_IMAGE_BYTES = 5 * 1024 * 1024
|
|
16
|
+
PNG_HEADER = b"\x89PNG\r\n\x1a\n"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def png_bounds(content: bytes) -> None:
|
|
20
|
+
if len(content) > MAX_IMAGE_BYTES:
|
|
21
|
+
raise Stop("ARTIFACT_LIMIT", "UNAVAILABLE")
|
|
22
|
+
if not content.startswith(PNG_HEADER):
|
|
23
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
24
|
+
offset, chunks = 8, []
|
|
25
|
+
while offset < len(content):
|
|
26
|
+
if offset + 12 > len(content):
|
|
27
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
28
|
+
size = int.from_bytes(content[offset:offset + 4], "big")
|
|
29
|
+
kind = content[offset + 4:offset + 8]
|
|
30
|
+
end = offset + 8 + size
|
|
31
|
+
if end + 4 > len(content) or kind not in (b"IHDR", b"IDAT", b"IEND", b"sRGB"):
|
|
32
|
+
# In particular, never retain PNG text/EXIF chunks as a hidden text channel.
|
|
33
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
34
|
+
if zlib.crc32(content[offset + 4:end]) != int.from_bytes(content[end:end + 4], "big"):
|
|
35
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
36
|
+
if kind == b"IHDR":
|
|
37
|
+
if chunks or size != 13:
|
|
38
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
39
|
+
width, height, depth, color, compression, filtering, interlace = struct.unpack(
|
|
40
|
+
">IIBBBBB", content[offset + 8:end])
|
|
41
|
+
if (not 1 <= width <= 1280 or not 1 <= height <= 4096 or depth != 8 or color not in (2, 6)
|
|
42
|
+
or compression or filtering or interlace):
|
|
43
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
44
|
+
if (kind == b"sRGB" and (size != 1 or content[offset + 8] > 3)
|
|
45
|
+
or kind == b"IEND" and size != 0 or len(chunks) >= 1024):
|
|
46
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
47
|
+
chunks.append(kind)
|
|
48
|
+
offset = end + 4
|
|
49
|
+
if not chunks or chunks[0] != b"IHDR" or chunks[-1] != b"IEND" or b"IDAT" not in chunks:
|
|
50
|
+
raise Stop("CAPTURE_PNG_INVALID")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Artifacts:
|
|
54
|
+
def __init__(self, policy: ArtifactPolicy, name: str, root_fd: int, directory_fd: int) -> None:
|
|
55
|
+
self.policy, self.name = policy, name
|
|
56
|
+
self.root_fd, self.directory_fd = root_fd, directory_fd
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def create(cls, policy: ArtifactPolicy) -> Artifacts:
|
|
60
|
+
root = private_directory(policy.root, "ARTIFACT_UNSAFE")
|
|
61
|
+
name = "run-" + uuid4().hex
|
|
62
|
+
made = False
|
|
63
|
+
try:
|
|
64
|
+
os.mkdir(name, mode=0o700, dir_fd=root)
|
|
65
|
+
made = True
|
|
66
|
+
directory = os.open(name, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=root)
|
|
67
|
+
except (OSError, Stop):
|
|
68
|
+
if made:
|
|
69
|
+
os.rmdir(name, dir_fd=root)
|
|
70
|
+
os.close(root)
|
|
71
|
+
raise
|
|
72
|
+
result = cls(policy, name, root, directory)
|
|
73
|
+
try:
|
|
74
|
+
result.validate()
|
|
75
|
+
except (OSError, Stop):
|
|
76
|
+
try:
|
|
77
|
+
result.discard()
|
|
78
|
+
finally:
|
|
79
|
+
result.close()
|
|
80
|
+
raise
|
|
81
|
+
return result
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def attach(cls, policy: ArtifactPolicy, name: str, inherited_fd: int) -> Artifacts:
|
|
85
|
+
if re.fullmatch(r"run-[0-9a-f]{32}", name) is None:
|
|
86
|
+
raise Stop("ARTIFACT_UNSAFE")
|
|
87
|
+
root = private_directory(policy.root, "ARTIFACT_UNSAFE")
|
|
88
|
+
try:
|
|
89
|
+
directory = os.dup(inherited_fd)
|
|
90
|
+
except OSError:
|
|
91
|
+
os.close(root)
|
|
92
|
+
raise
|
|
93
|
+
result = cls(policy, name, root, directory)
|
|
94
|
+
try:
|
|
95
|
+
result.validate()
|
|
96
|
+
except (OSError, Stop):
|
|
97
|
+
result.close()
|
|
98
|
+
raise
|
|
99
|
+
return result
|
|
100
|
+
|
|
101
|
+
def validate(self) -> None:
|
|
102
|
+
current = private_directory(self.policy.root, "ARTIFACT_UNSAFE")
|
|
103
|
+
try:
|
|
104
|
+
root = os.fstat(self.root_fd)
|
|
105
|
+
reopened = os.fstat(current)
|
|
106
|
+
directory = os.fstat(self.directory_fd)
|
|
107
|
+
try:
|
|
108
|
+
named = os.stat(self.name, dir_fd=current, follow_symlinks=False)
|
|
109
|
+
except OSError:
|
|
110
|
+
raise Stop("ARTIFACT_UNSAFE") from None
|
|
111
|
+
if ((root.st_dev, root.st_ino) != (reopened.st_dev, reopened.st_ino)
|
|
112
|
+
or (directory.st_dev, directory.st_ino) != (named.st_dev, named.st_ino)
|
|
113
|
+
or not stat.S_ISDIR(named.st_mode) or directory.st_uid != os.geteuid()
|
|
114
|
+
or stat.S_IMODE(directory.st_mode) != 0o700):
|
|
115
|
+
raise Stop("ARTIFACT_UNSAFE")
|
|
116
|
+
finally:
|
|
117
|
+
os.close(current)
|
|
118
|
+
|
|
119
|
+
def save(self, number: int, content: bytes) -> None:
|
|
120
|
+
if type(number) is not int or not 0 <= number < MAX_IMAGES:
|
|
121
|
+
raise Stop("ARTIFACT_LIMIT", "UNAVAILABLE")
|
|
122
|
+
png_bounds(content)
|
|
123
|
+
self.validate()
|
|
124
|
+
name = f"capture-{number}.png"
|
|
125
|
+
# No pathname is given to Playwright. Only checked in-memory PNG bytes reach
|
|
126
|
+
# an exclusively-created descriptor in this run's already-open directory.
|
|
127
|
+
fd = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o600, dir_fd=self.directory_fd)
|
|
128
|
+
try:
|
|
129
|
+
info = os.fstat(fd)
|
|
130
|
+
if (not stat.S_ISREG(info.st_mode) or info.st_uid != os.geteuid()
|
|
131
|
+
or stat.S_IMODE(info.st_mode) != 0o600 or info.st_nlink != 1):
|
|
132
|
+
raise Stop("ARTIFACT_UNSAFE")
|
|
133
|
+
remaining = memoryview(content)
|
|
134
|
+
while remaining:
|
|
135
|
+
written = os.write(fd, remaining)
|
|
136
|
+
if not written:
|
|
137
|
+
raise Stop("CAPTURE_WRITE_FAILED")
|
|
138
|
+
remaining = remaining[written:]
|
|
139
|
+
os.fsync(fd)
|
|
140
|
+
except (OSError, Stop):
|
|
141
|
+
os.unlink(name, dir_fd=self.directory_fd)
|
|
142
|
+
raise
|
|
143
|
+
finally:
|
|
144
|
+
os.close(fd)
|
|
145
|
+
|
|
146
|
+
def paths(self, expected: int) -> list[str]:
|
|
147
|
+
self.validate()
|
|
148
|
+
paths = []
|
|
149
|
+
for number in range(MAX_IMAGES):
|
|
150
|
+
name = f"capture-{number}.png"
|
|
151
|
+
try:
|
|
152
|
+
fd = os.open(name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=self.directory_fd)
|
|
153
|
+
except FileNotFoundError:
|
|
154
|
+
continue
|
|
155
|
+
with os.fdopen(fd, "rb") as stream:
|
|
156
|
+
info = os.fstat(stream.fileno())
|
|
157
|
+
if (not stat.S_ISREG(info.st_mode) or info.st_uid != os.geteuid()
|
|
158
|
+
or stat.S_IMODE(info.st_mode) != 0o600 or info.st_nlink != 1
|
|
159
|
+
or not 1 <= info.st_size <= MAX_IMAGE_BYTES):
|
|
160
|
+
raise Stop("ARTIFACT_UNSAFE")
|
|
161
|
+
png_bounds(stream.read(MAX_IMAGE_BYTES + 1))
|
|
162
|
+
paths.append(str(self.policy.root / self.name / name))
|
|
163
|
+
if len(paths) != expected:
|
|
164
|
+
raise Stop("CAPTURE_INCOMPLETE", "UNAVAILABLE")
|
|
165
|
+
return paths
|
|
166
|
+
|
|
167
|
+
def discard(self) -> None:
|
|
168
|
+
# This namespace was created exclusively for this run. Unlinking these fixed
|
|
169
|
+
# names never follows a symlink or touches any other run under the root.
|
|
170
|
+
for number in range(MAX_IMAGES):
|
|
171
|
+
try:
|
|
172
|
+
os.unlink(f"capture-{number}.png", dir_fd=self.directory_fd)
|
|
173
|
+
except FileNotFoundError:
|
|
174
|
+
pass
|
|
175
|
+
named = os.stat(self.name, dir_fd=self.root_fd, follow_symlinks=False)
|
|
176
|
+
owned = os.fstat(self.directory_fd)
|
|
177
|
+
if (named.st_dev, named.st_ino) != (owned.st_dev, owned.st_ino) or not stat.S_ISDIR(named.st_mode):
|
|
178
|
+
raise Stop("ARTIFACT_UNSAFE")
|
|
179
|
+
os.rmdir(self.name, dir_fd=self.root_fd)
|
|
180
|
+
|
|
181
|
+
def close(self) -> None:
|
|
182
|
+
try:
|
|
183
|
+
os.close(self.directory_fd)
|
|
184
|
+
finally:
|
|
185
|
+
os.close(self.root_fd)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# A deny-by-default mask inventory: keep only an independently expected selected
|
|
189
|
+
# title or the fixed receipt-state vocabulary. Unexpected ancestor text fails
|
|
190
|
+
# rather than escaping between masks. No DOM/text inventory leaves the page.
|
|
191
|
+
PREPARE = """(root, input) => {
|
|
192
|
+
const nodes = [root, ...root.querySelectorAll('*')];
|
|
193
|
+
if (nodes.length > 512) return {safe:false};
|
|
194
|
+
let allowed = [];
|
|
195
|
+
if (input.kind === 'session-title' || input.kind === 'layout') {
|
|
196
|
+
const title = root.querySelector('.session-title');
|
|
197
|
+
if (input.title && title && !title.children.length && title.textContent === input.title) allowed = [title];
|
|
198
|
+
} else if (input.kind === 'history-receipt') {
|
|
199
|
+
const safe = new Set(['zapis: tak','zapis: —','przekazanie: tak','przekazanie: —',
|
|
200
|
+
'ACK: tak','ACK: —','odpowiedź: tak','odpowiedź: —']);
|
|
201
|
+
allowed = [...root.querySelectorAll('.receipt-summary .receipt-state')]
|
|
202
|
+
.filter(n => !n.children.length && safe.has(n.textContent));
|
|
203
|
+
}
|
|
204
|
+
const keep = n => allowed.includes(n) || allowed.some(a => n.contains(a));
|
|
205
|
+
if (allowed.length && nodes.some(n => keep(n) && !allowed.includes(n) &&
|
|
206
|
+
[...n.childNodes].some(c => c.nodeType === Node.TEXT_NODE && c.textContent.trim()))) return {safe:false};
|
|
207
|
+
const masked = allowed.length ? nodes.filter(n => !keep(n)) : [root];
|
|
208
|
+
if (!masked.length) return {safe:false};
|
|
209
|
+
root.setAttribute('data-agent-chat-verify-component', input.nonce);
|
|
210
|
+
for (const node of masked) node.setAttribute('data-agent-chat-verify-mask', input.nonce);
|
|
211
|
+
const state = {root, masked, dirty:false, nonce:input.nonce};
|
|
212
|
+
state.observer = new MutationObserver(() => { state.dirty = true; });
|
|
213
|
+
state.observer.observe(root, {subtree:true, childList:true, characterData:true, attributes:true});
|
|
214
|
+
window.__agentChatCapture = state;
|
|
215
|
+
return {safe:true, count:masked.length};
|
|
216
|
+
}"""
|
|
217
|
+
VERIFY = """(root, nonce) => {
|
|
218
|
+
const s = window.__agentChatCapture;
|
|
219
|
+
return Boolean(s && s.root === root && s.nonce === nonce && !s.dirty && !s.observer.takeRecords().length &&
|
|
220
|
+
s.masked.every(n => n.isConnected && n.getAttribute('data-agent-chat-verify-mask') === nonce));
|
|
221
|
+
}"""
|
|
222
|
+
REMOVE = """() => {
|
|
223
|
+
const s = window.__agentChatCapture;
|
|
224
|
+
if (!s) return;
|
|
225
|
+
s.observer.disconnect(); s.root.removeAttribute('data-agent-chat-verify-component');
|
|
226
|
+
for (const n of s.masked) n.removeAttribute('data-agent-chat-verify-mask');
|
|
227
|
+
delete window.__agentChatCapture;
|
|
228
|
+
}"""
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
async def capture(request: Request, page: Any, artifacts: Artifacts, number: int, *, viewer: bool) -> None:
|
|
232
|
+
if not viewer or not await page.locator("#viewer[data-access='viewer']").is_visible():
|
|
233
|
+
raise Stop("CAPTURE_ACCESS_MISMATCH")
|
|
234
|
+
if request.scenario in ("session-title", "layout"):
|
|
235
|
+
selector = f"#participants > li[data-session-id='{request.session}']"
|
|
236
|
+
elif request.scenario == "history-receipt":
|
|
237
|
+
selector = f"#messages > li[data-message-id='{request.message}']"
|
|
238
|
+
else:
|
|
239
|
+
selector = "#read-only-indicator"
|
|
240
|
+
component = page.locator(selector)
|
|
241
|
+
nonce = uuid4().hex
|
|
242
|
+
content = None
|
|
243
|
+
try:
|
|
244
|
+
if await component.count() != 1 or not await component.is_visible():
|
|
245
|
+
raise Stop("CAPTURE_COMPONENT_UNAVAILABLE", "UNAVAILABLE")
|
|
246
|
+
box = await component.bounding_box()
|
|
247
|
+
if box is None or not 1 <= box["width"] <= 1280 or not 1 <= box["height"] <= 4096:
|
|
248
|
+
raise Stop("ARTIFACT_LIMIT", "UNAVAILABLE")
|
|
249
|
+
prepared = await component.evaluate(PREPARE, {"kind": request.scenario,
|
|
250
|
+
"title": request.expected_title, "nonce": nonce})
|
|
251
|
+
masks = page.locator(f'[data-agent-chat-verify-mask="{nonce}"]')
|
|
252
|
+
if not prepared.get("safe") or await masks.count() != prepared["count"]:
|
|
253
|
+
raise Stop("CAPTURE_MASK_FAILED")
|
|
254
|
+
# Exclude unrelated overlays outside the selected component as well as
|
|
255
|
+
# masking private descendants with opaque black rectangles, never blur.
|
|
256
|
+
visible = f'[data-agent-chat-verify-component="{nonce}"]'
|
|
257
|
+
style = ("body * {visibility:hidden !important; background-image:none !important} "
|
|
258
|
+
f"{visible}, {visible} * {{visibility:visible !important}} "
|
|
259
|
+
"*::before,*::after,*::marker {content:none !important}")
|
|
260
|
+
content = await component.screenshot(type="png", mask=[masks], mask_color="#000000",
|
|
261
|
+
animations="disabled", caret="hide", style=style, timeout=5000)
|
|
262
|
+
if not await component.evaluate(VERIFY, nonce):
|
|
263
|
+
raise Stop("CAPTURE_MASK_FAILED")
|
|
264
|
+
except Stop:
|
|
265
|
+
raise
|
|
266
|
+
except Exception:
|
|
267
|
+
raise Stop("CAPTURE_FAILED") from None
|
|
268
|
+
finally:
|
|
269
|
+
# A cleanup failure must also discard the in-memory capture; never fall
|
|
270
|
+
# back to an unmasked image or a different component.
|
|
271
|
+
try:
|
|
272
|
+
await page.evaluate(REMOVE)
|
|
273
|
+
except Exception:
|
|
274
|
+
raise Stop("CAPTURE_MASK_FAILED") from None
|
|
275
|
+
if content is None:
|
|
276
|
+
raise Stop("CAPTURE_FAILED")
|
|
277
|
+
try:
|
|
278
|
+
artifacts.save(number, content)
|
|
279
|
+
except OSError:
|
|
280
|
+
raise Stop("CAPTURE_WRITE_FAILED") from None
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Named read assertions; expected private text stays in memory, never in evidence."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any
|
|
5
|
+
from urllib.parse import urlencode
|
|
6
|
+
|
|
7
|
+
from .browser_verify import MAX_PAGES, Request, Stop, record, uuid_text
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def require(condition: bool, code: str) -> None:
|
|
11
|
+
if not condition:
|
|
12
|
+
raise Stop(code)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def identity(row: dict[str, Any]) -> str:
|
|
16
|
+
# This is the documented presentation contract, not the browser's renderer helper.
|
|
17
|
+
return f"{row.get('harness') or 'Agent'}" + (f" · {row['host']}" if row.get("host") else "") + \
|
|
18
|
+
f" · {row['session_id'][:8]}"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def presented(batch: list[dict[str, Any]], ids: list[str]) -> list[str]:
|
|
22
|
+
# The roster lists online sessions first and keeps the API order inside each group: the stable partition the page
|
|
23
|
+
# applies to the one page it renders. The row set stays exact, so a missing, repeated or retargeted id differs.
|
|
24
|
+
return [i for row, i in zip(batch, ids, strict=True) if row.get("online")] + \
|
|
25
|
+
[i for row, i in zip(batch, ids, strict=True) if not row.get("online")]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
async def text(locator: Any, expected: str, code: str) -> None:
|
|
29
|
+
await require(await locator.count() == 1 and await locator.text_content() == expected, code)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def read_only(page: Any) -> None:
|
|
33
|
+
controls = page.locator(
|
|
34
|
+
"#composer input, #composer textarea, #composer button, #create-room input, #create-room button, "
|
|
35
|
+
"#join-room input, #join-room button, .reply, .mute-session, .pm-session, .resolve-thread"
|
|
36
|
+
)
|
|
37
|
+
for control in await controls.all():
|
|
38
|
+
await require(not (await control.is_visible() and await control.is_enabled()), "MUTATION_CONTROL_ENABLED")
|
|
39
|
+
await require(await page.locator("#viewer[data-access='viewer']").is_visible(), "VIEWER_MISMATCH")
|
|
40
|
+
await require(await page.locator("#read-only-indicator").is_visible(), "READ_ONLY_INDICATOR_MISSING")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def select_room(request: Request, fence: Any, page: Any) -> None:
|
|
44
|
+
fence.healthy()
|
|
45
|
+
await page.locator("#viewer[data-access='viewer']").wait_for(state="visible")
|
|
46
|
+
await page.locator("#read-only-indicator").wait_for(state="visible")
|
|
47
|
+
options = await page.locator("#room option").evaluate_all("nodes => nodes.map(n => n.value).filter(Boolean)")
|
|
48
|
+
if not set(options) <= set(fence.binding.room_ids):
|
|
49
|
+
raise Stop("ROOM_SCOPE_MISMATCH")
|
|
50
|
+
if request.room not in options:
|
|
51
|
+
raise Stop("ROOM_UNAVAILABLE", "UNAVAILABLE")
|
|
52
|
+
if await page.locator("#room").input_value() != request.room:
|
|
53
|
+
async with page.expect_response(lambda response: f"/v1/rooms/{request.room}/participants?" in response.url):
|
|
54
|
+
await page.locator("#room").select_option(request.room)
|
|
55
|
+
await page.wait_for_load_state("networkidle")
|
|
56
|
+
fence.healthy()
|
|
57
|
+
await require(await page.locator("#room").input_value() == request.room, "ROOM_MISMATCH")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def collection(request: Request, fence: Any, context: Any, page: Any, kind: str,
|
|
61
|
+
*, target: str | None = None) -> list[dict[str, Any]]:
|
|
62
|
+
participants = kind == "participants"
|
|
63
|
+
key, attr = ("participants", "session-id") if participants else ("messages", "message-id")
|
|
64
|
+
id_key = "session_id" if participants else "id"
|
|
65
|
+
button = page.locator("#more-participants" if participants else "#more-messages")
|
|
66
|
+
query = {"limit": "50"}
|
|
67
|
+
if not participants:
|
|
68
|
+
query["before"] = "9223372036854775807"
|
|
69
|
+
rows = []
|
|
70
|
+
if participants and await page.locator("#participants-details").get_attribute("open") is None:
|
|
71
|
+
await page.locator("#participants-details > summary").click()
|
|
72
|
+
for number in range(MAX_PAGES):
|
|
73
|
+
data = await fence.api(context, f"/v1/rooms/{request.room}/{kind}?{urlencode(query)}")
|
|
74
|
+
batch = data.get(key)
|
|
75
|
+
if not isinstance(batch, list) or len(batch) > 50 or not all(isinstance(row, dict) for row in batch):
|
|
76
|
+
raise Stop("API_SHAPE_MISMATCH")
|
|
77
|
+
ids = [uuid_text(row[id_key]) for row in batch]
|
|
78
|
+
if len(ids) != len(set(ids)):
|
|
79
|
+
raise Stop("API_SHAPE_MISMATCH")
|
|
80
|
+
# networkidle is a navigation milestone, not an AJAX-render barrier.
|
|
81
|
+
# Wait for the exact API snapshot after room/page changes; persistent
|
|
82
|
+
# contrary DOM still fails within the bounded assertion timeout.
|
|
83
|
+
# The roster is shown in its presentation order; the history keeps the API order.
|
|
84
|
+
shown = presented(batch, ids) if participants else ids
|
|
85
|
+
try:
|
|
86
|
+
await page.wait_for_function("""input => JSON.stringify(
|
|
87
|
+
[...document.querySelectorAll(input.selector)].map(n => n.getAttribute(input.attribute))
|
|
88
|
+
) === JSON.stringify(input.ids)""",
|
|
89
|
+
arg={"selector": f"#{key} > li[data-{attr}]", "attribute": f"data-{attr}", "ids": shown},
|
|
90
|
+
timeout=5000)
|
|
91
|
+
except Exception:
|
|
92
|
+
fence.healthy()
|
|
93
|
+
raise Stop("PARTICIPANT_IDS_MISMATCH" if participants else "MESSAGE_IDS_MISMATCH") from None
|
|
94
|
+
rows.extend(batch)
|
|
95
|
+
if target is not None and target in ids:
|
|
96
|
+
return batch
|
|
97
|
+
if participants:
|
|
98
|
+
cursor = data.get("next_session_id")
|
|
99
|
+
if cursor is not None:
|
|
100
|
+
uuid_text(cursor)
|
|
101
|
+
more = cursor is not None
|
|
102
|
+
else:
|
|
103
|
+
more = data.get("has_more")
|
|
104
|
+
if type(more) is not bool:
|
|
105
|
+
raise Stop("API_SHAPE_MISMATCH")
|
|
106
|
+
cursor = data.get("next_cursor")
|
|
107
|
+
if not isinstance(cursor, str) or not cursor.isdecimal():
|
|
108
|
+
raise Stop("API_SHAPE_MISMATCH")
|
|
109
|
+
await require(await button.is_visible() == more, "PAGINATION_CONTROL_MISMATCH")
|
|
110
|
+
if not more:
|
|
111
|
+
if target is not None:
|
|
112
|
+
raise Stop("SESSION_UNAVAILABLE" if participants else "MESSAGE_UNAVAILABLE", "UNAVAILABLE")
|
|
113
|
+
return rows
|
|
114
|
+
if number == MAX_PAGES - 1:
|
|
115
|
+
raise Stop("PAGE_LIMIT", "UNAVAILABLE")
|
|
116
|
+
query["after_session" if participants else "before"] = cursor
|
|
117
|
+
async with page.expect_response(lambda response: f"/{kind}?" in response.url):
|
|
118
|
+
await button.click()
|
|
119
|
+
await page.wait_for_load_state("networkidle")
|
|
120
|
+
fence.healthy()
|
|
121
|
+
raise Stop("PAGE_LIMIT", "UNAVAILABLE")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def participant(request: Request, rows: list[dict[str, Any]], page: Any) -> None:
|
|
125
|
+
row = next((row for row in rows if row["session_id"] == request.session), None)
|
|
126
|
+
if row is None:
|
|
127
|
+
raise Stop("SESSION_UNAVAILABLE", "UNAVAILABLE")
|
|
128
|
+
title = row["title"]
|
|
129
|
+
if title is not None and not isinstance(title, str):
|
|
130
|
+
raise Stop("API_SHAPE_MISMATCH")
|
|
131
|
+
if request.expected_title is not None:
|
|
132
|
+
await require((title or "") == request.expected_title, "EXPECTED_TITLE_MISMATCH")
|
|
133
|
+
node = page.locator(f"#participants > li[data-session-id='{request.session}']")
|
|
134
|
+
await require(await node.count() == 1, "SESSION_DOM_MISSING")
|
|
135
|
+
await text(node.locator(".participant-id"), request.session or "", "SESSION_UUID_MISMATCH")
|
|
136
|
+
await text(node.locator(".participant-label"), row["label"], "SESSION_LABEL_MISMATCH")
|
|
137
|
+
await text(node.locator(".session-title"), title or identity(row), "TITLE_DOM_MISMATCH")
|
|
138
|
+
await require(await node.locator(".session-title *").count() == 0, "TITLE_MARKUP_ACTIVE")
|
|
139
|
+
await text(node.locator(".participant-identity"), identity(row), "SESSION_IDENTITY_MISMATCH")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
async def history_receipt(request: Request, rows: list[dict[str, Any]], page: Any) -> None:
|
|
143
|
+
message = next(row for row in rows if row["id"] == request.message)
|
|
144
|
+
await require(message["room_id"] == request.room, "MESSAGE_ROOM_MISMATCH")
|
|
145
|
+
receipts = message.get("receipts")
|
|
146
|
+
if not isinstance(receipts, list):
|
|
147
|
+
raise Stop("API_SHAPE_MISMATCH")
|
|
148
|
+
receipt = next((row for row in receipts if row["session_id"] == request.receipt_session), None)
|
|
149
|
+
if receipt is None:
|
|
150
|
+
raise Stop("RECEIPT_UNAVAILABLE", "UNAVAILABLE")
|
|
151
|
+
fields = {"stored": "stored_at", "handed": "handed_at", "acknowledged": "acknowledged_at",
|
|
152
|
+
"replied": "replying_message_id", "uncertain": "uncertainty_reason"}
|
|
153
|
+
for state in request.receipt_states:
|
|
154
|
+
await require(bool(receipt.get(fields[state])), "EXPECTED_RECEIPT_MISMATCH")
|
|
155
|
+
node = page.locator(f"#messages > li[data-message-id='{request.message}']")
|
|
156
|
+
await text(node.locator(".body"), message["body"], "MESSAGE_BODY_MISMATCH")
|
|
157
|
+
await require(await node.locator(".body *").count() == 0, "MESSAGE_MARKUP_ACTIVE")
|
|
158
|
+
sender = message["sender"]
|
|
159
|
+
if sender["session_id"] is None:
|
|
160
|
+
await text(node.locator(".sender-name"), "Operator", "SENDER_MISMATCH")
|
|
161
|
+
else:
|
|
162
|
+
await text(node.locator(".sender-name"), sender.get("title") or identity(sender), "SENDER_MISMATCH")
|
|
163
|
+
# An untitled session is named by its identity alone; only a titled one repeats it beneath the name.
|
|
164
|
+
if sender.get("title"):
|
|
165
|
+
await text(node.locator(".sender-identity"), identity(sender), "SENDER_IDENTITY_MISMATCH")
|
|
166
|
+
else:
|
|
167
|
+
await require(await node.locator(".sender-identity").count() == 0, "SENDER_IDENTITY_MISMATCH")
|
|
168
|
+
summaries = node.locator(".receipt-summary > li")
|
|
169
|
+
await require(await summaries.count() == len(receipts), "RECEIPT_COUNT_MISMATCH")
|
|
170
|
+
await node.locator(".message-evidence > summary").click()
|
|
171
|
+
evidence = node.locator(".evidence-receipts > li")
|
|
172
|
+
await require(await evidence.count() == len(receipts), "RECEIPT_EVIDENCE_MISMATCH")
|
|
173
|
+
for index, row in enumerate(receipts):
|
|
174
|
+
states = [f"{label}: {'tak' if row.get(field) else '—'}"
|
|
175
|
+
for label, field in (("zapis", "stored_at"), ("przekazanie", "handed_at"),
|
|
176
|
+
("ACK", "acknowledged_at"), ("odpowiedź", "replying_message_id"))]
|
|
177
|
+
states += [f"niepewność: {row.get('uncertainty_reason') or '—'}",
|
|
178
|
+
f"próba: {(row.get('delivery') or {}).get('outcome') or '—'}"]
|
|
179
|
+
await require(await summaries.nth(index).locator(".receipt-state").all_text_contents() == states,
|
|
180
|
+
"RECEIPT_STATE_DOM_MISMATCH")
|
|
181
|
+
expected = (f"{row['session_id']} · zapis: {row.get('stored_at') or '—'} · "
|
|
182
|
+
f"przekazanie: {row.get('handed_at') or '—'} · ACK: {row.get('acknowledged_at') or '—'} · "
|
|
183
|
+
f"odpowiedź: {row.get('replying_message_id') or '—'} · "
|
|
184
|
+
f"niepewność: {row.get('uncertainty_reason') or '—'} · "
|
|
185
|
+
f"próba: {(row.get('delivery') or {}).get('outcome') or '—'}")
|
|
186
|
+
await text(evidence.nth(index), expected, "RECEIPT_EVIDENCE_MISMATCH")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
async def layout(page: Any) -> None:
|
|
190
|
+
await require(await page.evaluate("document.documentElement.scrollWidth <= window.innerWidth + 1"),
|
|
191
|
+
"DOCUMENT_OVERFLOW")
|
|
192
|
+
details = page.locator("#participants-details")
|
|
193
|
+
await details.locator(":scope > summary").click()
|
|
194
|
+
await require(await details.get_attribute("open") is None, "PANEL_COLLAPSE_MISMATCH")
|
|
195
|
+
await details.locator(":scope > summary").click()
|
|
196
|
+
await require(await details.get_attribute("open") is not None, "PANEL_EXPAND_MISMATCH")
|
|
197
|
+
for selector in ("#room", "#refresh", "#participants-details > summary", "#thread-filter", "#messages"):
|
|
198
|
+
control = page.locator(selector)
|
|
199
|
+
await require(await control.is_visible(), "READ_CONTROL_MISSING")
|
|
200
|
+
if selector != "#messages":
|
|
201
|
+
await control.scroll_into_view_if_needed()
|
|
202
|
+
box = await control.bounding_box()
|
|
203
|
+
width = await page.evaluate("window.innerWidth")
|
|
204
|
+
await require(box is not None and box["width"] > 0 and box["height"] > 0
|
|
205
|
+
and box["x"] >= -1 and box["x"] + box["width"] <= width + 1,
|
|
206
|
+
"READ_CONTROL_UNREACHABLE")
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
async def scenario(request: Request, fence: Any, context: Any, page: Any, viewport: int) -> None:
|
|
210
|
+
await read_only(page)
|
|
211
|
+
if request.scenario == "snapshot":
|
|
212
|
+
# Empty history is legitimate, but missing/retargeted API-to-DOM rows are not.
|
|
213
|
+
await collection(request, fence, context, page, "participants")
|
|
214
|
+
await collection(request, fence, context, page, "history")
|
|
215
|
+
record(fence.result, "SNAPSHOT_CONTENT", viewport=viewport)
|
|
216
|
+
elif request.scenario in ("session-title", "layout"):
|
|
217
|
+
if request.scenario == "layout":
|
|
218
|
+
# Full bounded enumeration establishes the live precondition, not a fixture claim.
|
|
219
|
+
rows = await collection(request, fence, context, page, "participants")
|
|
220
|
+
if len(rows) < (request.min_participants or 1):
|
|
221
|
+
raise Stop("LAYOUT_DATA_UNAVAILABLE", "UNAVAILABLE")
|
|
222
|
+
# Re-open the initial page; find the exact UUID, never a title match.
|
|
223
|
+
await fence.navigate(page, reload=True)
|
|
224
|
+
await select_room(request, fence, page)
|
|
225
|
+
rows = await collection(request, fence, context, page, "participants", target=request.session)
|
|
226
|
+
await participant(request, rows, page)
|
|
227
|
+
record(fence.result, "SESSION_TITLE", viewport=viewport)
|
|
228
|
+
if request.scenario == "layout":
|
|
229
|
+
await layout(page)
|
|
230
|
+
record(fence.result, "LAYOUT_GEOMETRY", viewport=viewport)
|
|
231
|
+
else:
|
|
232
|
+
rows = await collection(request, fence, context, page, "history", target=request.message)
|
|
233
|
+
await history_receipt(request, rows, page)
|
|
234
|
+
record(fence.result, "HISTORY_RECEIPT", viewport=viewport)
|
|
235
|
+
await read_only(page)
|
|
236
|
+
record(fence.result, "READ_ONLY_VIEW", viewport=viewport)
|