@raytrace-cli/cli 0.14.2 → 0.15.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.
- package/dist/dashboard/assets/index-B5ndFs_A.css +1 -0
- package/dist/dashboard/assets/{index-DF_klLF4.js → index-BnYr54S5.js} +5 -5
- package/dist/dashboard/index.html +2 -2
- package/package.json +1 -1
- package/src/local-sandbox.mjs +4 -1
- package/worker/sandbox/engine.py +91 -10
- package/worker/sandbox/test_capture.py +117 -0
- package/dist/dashboard/assets/index-CM-3AX0c.css +0 -1
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<title>RayTrace — Agent trace forensics</title>
|
|
7
7
|
<meta name="description" content="Evidence-backed traces and live counterfactual forks for coding agents." />
|
|
8
8
|
<link rel="icon" href="/favicon.svg?v=raytrace-box-1" type="image/svg+xml" />
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-BnYr54S5.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/index-B5ndFs_A.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body class="antialiased">
|
|
13
13
|
<div id="root"></div>
|
package/package.json
CHANGED
package/src/local-sandbox.mjs
CHANGED
|
@@ -108,7 +108,10 @@ export function vmStatus() {
|
|
|
108
108
|
|
|
109
109
|
function setupVersion() {
|
|
110
110
|
const hash = createHash('sha256');
|
|
111
|
-
|
|
111
|
+
// Files only: a __pycache__ left by running the tests there is no part of what is installed.
|
|
112
|
+
for (const entry of readdirSync(SOURCE, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
113
|
+
if (entry.isFile()) hash.update(entry.name).update(readFileSync(join(SOURCE, entry.name)));
|
|
114
|
+
}
|
|
112
115
|
return hash.digest('hex').slice(0, 16);
|
|
113
116
|
}
|
|
114
117
|
|
package/worker/sandbox/engine.py
CHANGED
|
@@ -7,10 +7,11 @@ keeps what matters as a fact, counts the rest and stores no event at all.
|
|
|
7
7
|
|
|
8
8
|
What matters:
|
|
9
9
|
|
|
10
|
-
files
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
the
|
|
10
|
+
files every file of the project (outside node_modules and the
|
|
11
|
+
like): created, changed, emptied, appended, deleted, renamed,
|
|
12
|
+
or an attempt the kernel refused. A read is a fact as well for
|
|
13
|
+
a file the project's owner restricted or watches and one whose
|
|
14
|
+
path marks it sensitive (a .env, a key); other reads are counted
|
|
14
15
|
network every connection out of the sandbox, one fact for each
|
|
15
16
|
destination a step reached, and whether the firewall refuses it
|
|
16
17
|
packages what a package manager left installed once it had run
|
|
@@ -83,6 +84,7 @@ ERRNO = {**REFUSED, 2: 'ENOENT', 101: 'ENETUNREACH', 110: 'ETIMEDOUT', 111: 'ECO
|
|
|
83
84
|
EINPROGRESS = 115
|
|
84
85
|
MAX_HASHED = 5 * 1024 * 1024 # a larger file is compared by size, time and inode
|
|
85
86
|
HASH_LIMIT = 2000 # with more files than this to keep, none is hashed up front
|
|
87
|
+
PROJECT_LIMIT = 20_000 # a project with more files than this keeps facts of listed and sensitive files only
|
|
86
88
|
SENSITIVE_FROM = 4 # file_scan's level from which a new file's path alone is worth a fact
|
|
87
89
|
SETTLE = 0.3 # seconds between a change seen on disk and looking: gVisor's call may still be on its way
|
|
88
90
|
WRITER_LIFE = 900 # how long an open for writing may explain a later change
|
|
@@ -174,6 +176,20 @@ def names_inside(root, path):
|
|
|
174
176
|
os.close(fd)
|
|
175
177
|
|
|
176
178
|
|
|
179
|
+
def link_inside(root, path):
|
|
180
|
+
"""Whether a project path is a symbolic link (read, not followed)."""
|
|
181
|
+
try:
|
|
182
|
+
folder = open_inside(root, posixpath.dirname(path), directory=True)
|
|
183
|
+
except (OSError, ValueError):
|
|
184
|
+
return False
|
|
185
|
+
try:
|
|
186
|
+
return stat.S_ISLNK(os.stat(posixpath.basename(path), dir_fd=folder, follow_symlinks=False).st_mode)
|
|
187
|
+
except OSError:
|
|
188
|
+
return False
|
|
189
|
+
finally:
|
|
190
|
+
os.close(folder)
|
|
191
|
+
|
|
192
|
+
|
|
177
193
|
def change(before, after, events, flags):
|
|
178
194
|
"""What happened to a file between two photos, or None when nothing did."""
|
|
179
195
|
if after is None:
|
|
@@ -252,6 +268,7 @@ class Inotify:
|
|
|
252
268
|
"""The host kernel's file notifications, for the folders of the files
|
|
253
269
|
worth a fact. It names the file a delete or rename hit, which gVisor does not."""
|
|
254
270
|
CLOSE_WRITE, MODIFY, ATTRIB, CREATE, DELETE, MOVED_FROM, MOVED_TO = 0x8, 0x2, 0x4, 0x100, 0x200, 0x40, 0x80
|
|
271
|
+
ISDIR = 0x40000000
|
|
255
272
|
DELETE_SELF, MOVE_SELF, OVERFLOW, IGNORED, ONLYDIR = 0x400, 0x800, 0x4000, 0x8000, 0x01000000
|
|
256
273
|
WORDS = [(CLOSE_WRITE, 'close_write'), (MODIFY, 'modify'), (ATTRIB, 'attrib'), (CREATE, 'create'), (DELETE, 'delete'),
|
|
257
274
|
(MOVED_FROM, 'moved_from'), (MOVED_TO, 'moved_to')]
|
|
@@ -298,7 +315,8 @@ class Sandbox:
|
|
|
298
315
|
self.fork = False
|
|
299
316
|
self.mapped = self.guarded_at = None # the two files' times, as last read
|
|
300
317
|
self.restricted, self.watched, self.sensitive = set(), set(), set()
|
|
301
|
-
self.
|
|
318
|
+
self.project = False # every project file is kept, not only the listed and sensitive ones
|
|
319
|
+
self.guarded = {} # path -> restricted | watched | sensitive | project
|
|
302
320
|
self.hashing = True
|
|
303
321
|
self.photos = {} # path -> its last photo; None: it was not there
|
|
304
322
|
self.known = None # project paths that exist, to tell a new file from an old one
|
|
@@ -489,7 +507,9 @@ class Engine(threading.Thread):
|
|
|
489
507
|
for folder, folders, files in os.walk(workspace):
|
|
490
508
|
folders[:] = [name for name in folders if name not in SKIPPED]
|
|
491
509
|
inside = os.path.relpath(folder, workspace)
|
|
492
|
-
|
|
510
|
+
# Not links: a link is a name for another file, and that file is the one kept.
|
|
511
|
+
box.known.update(name if inside == '.' else inside + '/' + name for name in files
|
|
512
|
+
if not os.path.islink(os.path.join(folder, name)))
|
|
493
513
|
if len(box.known) > 200_000:
|
|
494
514
|
break
|
|
495
515
|
box.packages = installed(workspace, box.home)
|
|
@@ -508,12 +528,17 @@ class Engine(threading.Thread):
|
|
|
508
528
|
kept = {}
|
|
509
529
|
box.restricted = {path for path in kept.get('restricted') or [] if isinstance(path, str)}
|
|
510
530
|
box.watched = {path for path in kept.get('watched') or [] if isinstance(path, str)}
|
|
531
|
+
# Every project file, unless the lists say `"project": false` or there are too many to watch.
|
|
532
|
+
box.project = kept.get('project') is not False and box.known is not None and len(box.known) <= PROJECT_LIMIT
|
|
533
|
+
if box.project:
|
|
534
|
+
box.sensitive.update(path for path in box.known if file_scan.created_entry(path)['level'] >= SENSITIVE_FROM)
|
|
511
535
|
self.guard(box)
|
|
512
536
|
self.arm(box)
|
|
513
537
|
|
|
514
538
|
def guard(self, box):
|
|
515
539
|
"""The files to keep facts of, each with a first photo to compare later ones with."""
|
|
516
|
-
guarded = {path: '
|
|
540
|
+
guarded = {path: 'project' for path in box.known} if box.project else {}
|
|
541
|
+
guarded.update({path: 'sensitive' for path in box.sensitive})
|
|
517
542
|
guarded.update({path: 'watched' for path in box.watched})
|
|
518
543
|
guarded.update({path: 'restricted' for path in box.restricted})
|
|
519
544
|
box.hashing = len(guarded) <= HASH_LIMIT
|
|
@@ -540,6 +565,20 @@ class Engine(threading.Thread):
|
|
|
540
565
|
box.watches[folder] = watch
|
|
541
566
|
self.watched[watch] = (box, folder)
|
|
542
567
|
|
|
568
|
+
def cover(self, box, path, first=None):
|
|
569
|
+
"""A project file that appeared while the sandbox ran: kept from now
|
|
570
|
+
on. `first` is what it is compared with: None, it was not there."""
|
|
571
|
+
box.known.add(path)
|
|
572
|
+
box.guarded[path], box.photos[path] = 'project', first
|
|
573
|
+
folder = posixpath.dirname(path)
|
|
574
|
+
if self.inotify and folder not in box.watches:
|
|
575
|
+
try:
|
|
576
|
+
watch = self.inotify.add(box.workspace, folder)
|
|
577
|
+
except (OSError, ValueError):
|
|
578
|
+
return
|
|
579
|
+
box.watches[folder] = watch
|
|
580
|
+
self.watched[watch] = (box, folder)
|
|
581
|
+
|
|
543
582
|
def unwatch(self, box, folder):
|
|
544
583
|
watch = box.watches.pop(folder, None)
|
|
545
584
|
if watch is not None and self.watched.pop(watch, None):
|
|
@@ -693,6 +732,9 @@ class Engine(threading.Thread):
|
|
|
693
732
|
self.guard(box)
|
|
694
733
|
self.arm(box)
|
|
695
734
|
guard = 'sensitive'
|
|
735
|
+
elif box.project and not link_inside(box.workspace, path):
|
|
736
|
+
self.cover(box, path)
|
|
737
|
+
guard = 'project'
|
|
696
738
|
if guard is None:
|
|
697
739
|
if writing and not errno and box.guarded:
|
|
698
740
|
box.aliases.append({'path': path, 'who': who, 'at_ns': at_ns, 'syscall': self.calls.get(event.get('sysno'), ('open', 'open'))[0]})
|
|
@@ -706,10 +748,14 @@ class Engine(threading.Thread):
|
|
|
706
748
|
'basis': {**basis, 'errno': REFUSED[errno]}}, at_ns)
|
|
707
749
|
return
|
|
708
750
|
if not writing:
|
|
751
|
+
if guard == 'project': # reads of ordinary files are counted, as before: a test run reads hundreds
|
|
752
|
+
return self.counted(box, who, top, at_ns)
|
|
709
753
|
self.fact(box, 'file', (path, 'read'), who, {'path': path, 'guard': guard, 'effect': 'read', 'certainty': 'confirmed',
|
|
710
754
|
'basis': {**basis, 'note': 'opened for reading; the bytes read are not captured'}}, at_ns)
|
|
711
755
|
return
|
|
712
756
|
now = self.clock()
|
|
757
|
+
if guard == 'project': # it may be a hard link to another kept file: see linked()
|
|
758
|
+
box.aliases.append({'path': path, 'who': who, 'at_ns': at_ns, 'syscall': call})
|
|
713
759
|
box.writers.setdefault(path, []).append({'who': who, 'at_ns': at_ns, 'flags': flags, 'syscall': call, 'credited': False, 'seen': now})
|
|
714
760
|
box.due[path] = min(box.due.get(path, now + 1), now + 1)
|
|
715
761
|
box.final[path] = now + 30
|
|
@@ -753,8 +799,9 @@ class Engine(threading.Thread):
|
|
|
753
799
|
if not at or path.startswith(at + '/'):
|
|
754
800
|
found.setdefault(path, 'argv_folder')
|
|
755
801
|
if not found:
|
|
802
|
+
# Not for ordinary project files: a short name is in any text.
|
|
756
803
|
text = ' '.join(who.get('argv') or [])
|
|
757
|
-
found = {path: 'argv_text' for path in box.guarded if path in text}
|
|
804
|
+
found = {path: 'argv_text' for path, guard in box.guarded.items() if guard != 'project' and path in text}
|
|
758
805
|
return sorted(found.items())[:5]
|
|
759
806
|
|
|
760
807
|
def actors(self, box, rule, at_ns, path):
|
|
@@ -775,6 +822,9 @@ class Engine(threading.Thread):
|
|
|
775
822
|
events = self.inotify.read()
|
|
776
823
|
moved = {cookie: posixpath.join(self.watched[watch][1], name) for watch, mask, cookie, name in events
|
|
777
824
|
if mask & Inotify.MOVED_TO and watch in self.watched}
|
|
825
|
+
# Kept files that were renamed: the new name is the same file, not a new one.
|
|
826
|
+
renamed = {cookie for watch, mask, cookie, name in events if mask & Inotify.MOVED_FROM and watch in self.watched
|
|
827
|
+
and posixpath.join(self.watched[watch][1], name) in self.watched[watch][0].guarded}
|
|
778
828
|
for watch, mask, cookie, name in events:
|
|
779
829
|
if mask & Inotify.OVERFLOW: # the kernel dropped notices: look at everything again
|
|
780
830
|
for box in self.boxes.values():
|
|
@@ -796,11 +846,34 @@ class Engine(threading.Thread):
|
|
|
796
846
|
self.noticed(box, path, [])
|
|
797
847
|
continue
|
|
798
848
|
path = posixpath.join(folder, name)
|
|
849
|
+
if path not in box.guarded and box.project and mask & (Inotify.CREATE | Inotify.MOVED_TO) and name not in SKIPPED:
|
|
850
|
+
self.appeared(box, path, bool(mask & Inotify.ISDIR), cookie in renamed)
|
|
799
851
|
if path in box.guarded:
|
|
800
852
|
self.noticed(box, path, [word for bit, word in Inotify.WORDS if mask & bit],
|
|
801
853
|
moved.get(cookie) if mask & Inotify.MOVED_FROM else None)
|
|
802
854
|
return len(events)
|
|
803
855
|
|
|
856
|
+
def appeared(self, box, path, folder, renamed):
|
|
857
|
+
"""A name the watcher saw arrive in a project that is kept whole, with
|
|
858
|
+
no open that created it: a file moved in, or a folder with its files."""
|
|
859
|
+
if not folder:
|
|
860
|
+
if len(box.guarded) < PROJECT_LIMIT:
|
|
861
|
+
# A kept file under its new name has its `renamed` fact already.
|
|
862
|
+
self.cover(box, path, photo(box.workspace, path, box.hashing) if renamed else None)
|
|
863
|
+
return
|
|
864
|
+
folders = [path]
|
|
865
|
+
while folders and len(box.guarded) < PROJECT_LIMIT:
|
|
866
|
+
at = folders.pop()
|
|
867
|
+
for name in names_inside(box.workspace, at):
|
|
868
|
+
below = posixpath.join(at, name)
|
|
869
|
+
if name in SKIPPED or below in box.guarded:
|
|
870
|
+
continue
|
|
871
|
+
if photo(box.workspace, below, False) is not None:
|
|
872
|
+
self.cover(box, below)
|
|
873
|
+
self.noticed(box, below, ['moved_to' if renamed else 'create'])
|
|
874
|
+
else:
|
|
875
|
+
folders.append(below) # no folder, or an empty one, lists nothing
|
|
876
|
+
|
|
804
877
|
def noticed(self, box, path, words, moved_to=None):
|
|
805
878
|
"""The watcher saw something of a file: look at it once things settle."""
|
|
806
879
|
cause = box.causes.setdefault(path, {'events': set(), 'at_ns': time.time_ns()})
|
|
@@ -822,7 +895,8 @@ class Engine(threading.Thread):
|
|
|
822
895
|
writers = box.writers[path] = [writer for writer in box.writers.get(path, [])
|
|
823
896
|
if now - writer['seen'] < WRITER_LIFE and not writer.get('settled')]
|
|
824
897
|
before = box.photos.get(path)
|
|
825
|
-
|
|
898
|
+
# With too many files to hash up front, one that was seen to change is still hashed here.
|
|
899
|
+
after = photo(box.workspace, path, box.hashing or (box.project and bool(cause['events'] or writers)))
|
|
826
900
|
flags = 0
|
|
827
901
|
for writer in writers:
|
|
828
902
|
flags |= writer['flags']
|
|
@@ -870,7 +944,9 @@ class Engine(threading.Thread):
|
|
|
870
944
|
fact['basis']['after'] = after
|
|
871
945
|
if cause.get('to'):
|
|
872
946
|
fact['to'] = cause['to']
|
|
873
|
-
elif final:
|
|
947
|
+
elif final and not (guard == 'project' and before is None and after is None):
|
|
948
|
+
# (An ordinary file that came and went between two looks, as the
|
|
949
|
+
# temporary file of an editor's save does, is not worth a line.)
|
|
874
950
|
for writer in writers:
|
|
875
951
|
if not writer['credited']:
|
|
876
952
|
writer['credited'] = True
|
|
@@ -883,6 +959,11 @@ class Engine(threading.Thread):
|
|
|
883
959
|
writer['settled'] = True
|
|
884
960
|
if not writers:
|
|
885
961
|
box.writers.pop(path, None)
|
|
962
|
+
if guard == 'project' and after is None and (effect or final):
|
|
963
|
+
# Gone: nothing more to compare. It is kept again if it comes back.
|
|
964
|
+
box.guarded.pop(path, None)
|
|
965
|
+
box.photos.pop(path, None)
|
|
966
|
+
box.known.discard(path)
|
|
886
967
|
|
|
887
968
|
def linked(self, box, path, after, at_ns):
|
|
888
969
|
"""A recent open for writing of another name that is this file: a hard
|
|
@@ -211,5 +211,122 @@ class FailedExecs(unittest.TestCase):
|
|
|
211
211
|
self.assertNotIn('raw_packet_base64', json.loads(json.dumps(failed)))
|
|
212
212
|
|
|
213
213
|
|
|
214
|
+
|
|
215
|
+
class EveryProjectFile(unittest.TestCase):
|
|
216
|
+
"""A project kept whole: what happens to any of its files is a fact, not
|
|
217
|
+
only to the files on a list."""
|
|
218
|
+
SID = 'rtp-' + 'a' * 32
|
|
219
|
+
|
|
220
|
+
def setUp(self):
|
|
221
|
+
self.now = 1000.0
|
|
222
|
+
self.engine = engine.Engine(':memory:', arch='aarch64', watch=False, clock=lambda: self.now)
|
|
223
|
+
self.folder = tempfile.TemporaryDirectory()
|
|
224
|
+
self.state = tempfile.TemporaryDirectory()
|
|
225
|
+
self.addCleanup(self.folder.cleanup)
|
|
226
|
+
self.addCleanup(self.state.cleanup)
|
|
227
|
+
for name in ('CONTAINERS', 'GUARDRAILS', 'PROJECT_LIMIT'):
|
|
228
|
+
self.addCleanup(setattr, engine, name, getattr(engine, name))
|
|
229
|
+
engine.CONTAINERS = engine.GUARDRAILS = Path(self.state.name)
|
|
230
|
+
for name, text in (('src/app.js', 'one'), ('config/payment-keys.js', 'key'), ('node_modules/x/index.js', 'x')):
|
|
231
|
+
self.write(name, text)
|
|
232
|
+
(Path(self.state.name) / ('c' * 64 + '.json')).write_text(json.dumps({'id': self.SID, 'workspace': self.folder.name}))
|
|
233
|
+
self.box = engine.Sandbox('c' * 64)
|
|
234
|
+
self.box.processes[10] = {'start_ns': '10', 'ppid': 1, 'name': 'sed', 'argv': ['sed'], 'call_id': 'call_10'}
|
|
235
|
+
|
|
236
|
+
def write(self, name, text):
|
|
237
|
+
path = Path(self.folder.name) / name
|
|
238
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
239
|
+
path.write_text(text)
|
|
240
|
+
|
|
241
|
+
def opened(self, name, flags=engine.O_TRUNC | 1):
|
|
242
|
+
self.engine.opened(self.box, {'kind': 'open', 'pathname': '/workspace/' + name, 'flags': flags, 'errno': 0, 'pid': 10,
|
|
243
|
+
'ppid': 1, 'process_start_ns': '10', 'timestamp_ns': str(time.time_ns()), 'sysno': 56})
|
|
244
|
+
|
|
245
|
+
def looked(self, name, *words, final=False):
|
|
246
|
+
if words:
|
|
247
|
+
self.engine.noticed(self.box, name, list(words))
|
|
248
|
+
self.engine.look(self.box, name, final=final)
|
|
249
|
+
return [(fact['path'], fact['effect'], fact['guard'], fact['call_id']) for fact in self.engine.facts.values() if fact['kind'] == 'file']
|
|
250
|
+
|
|
251
|
+
def test_every_file_outside_the_skipped_folders_is_kept(self):
|
|
252
|
+
self.engine.refresh(self.box)
|
|
253
|
+
self.assertEqual(self.box.guarded, {'src/app.js': 'project', 'config/payment-keys.js': 'sensitive'})
|
|
254
|
+
|
|
255
|
+
def test_the_lists_can_turn_it_off_and_a_huge_project_is_not_kept_whole(self):
|
|
256
|
+
(Path(self.state.name) / (self.SID + '.json')).write_text(json.dumps({'restricted': [], 'watched': ['src/app.js'], 'project': False}))
|
|
257
|
+
self.engine.refresh(self.box)
|
|
258
|
+
self.assertEqual(self.box.guarded, {'src/app.js': 'watched'})
|
|
259
|
+
engine.PROJECT_LIMIT = 1
|
|
260
|
+
other = engine.Sandbox('c' * 64)
|
|
261
|
+
(Path(self.state.name) / (self.SID + '.json')).unlink()
|
|
262
|
+
self.engine.refresh(other)
|
|
263
|
+
self.assertEqual(other.guarded, {})
|
|
264
|
+
|
|
265
|
+
def test_an_edit_is_a_fact_and_a_read_is_counted(self):
|
|
266
|
+
self.engine.refresh(self.box)
|
|
267
|
+
self.opened('src/app.js', flags=0)
|
|
268
|
+
self.assertEqual(self.looked('src/app.js'), [])
|
|
269
|
+
self.opened('src/app.js')
|
|
270
|
+
self.write('src/app.js', 'two')
|
|
271
|
+
self.assertEqual(self.looked('src/app.js', 'modify', 'close_write'), [('src/app.js', 'changed', 'project', 'call_10')])
|
|
272
|
+
# A sensitive file that was there from the start: its read is a fact too.
|
|
273
|
+
self.opened('config/payment-keys.js', flags=0)
|
|
274
|
+
self.assertIn(('config/payment-keys.js', 'read', 'sensitive', 'call_10'), self.looked('config/payment-keys.js'))
|
|
275
|
+
|
|
276
|
+
def test_a_new_file_is_created_and_a_deleted_one_is_let_go(self):
|
|
277
|
+
self.engine.refresh(self.box)
|
|
278
|
+
self.opened('src/new.js', flags=engine.O_CREAT | 1)
|
|
279
|
+
self.write('src/new.js', 'new')
|
|
280
|
+
self.assertEqual(self.looked('src/new.js', 'create', 'close_write'), [('src/new.js', 'created', 'project', 'call_10')])
|
|
281
|
+
(Path(self.folder.name) / 'src/new.js').unlink()
|
|
282
|
+
self.assertIn(('src/new.js', 'deleted', 'project', None), self.looked('src/new.js', 'delete'))
|
|
283
|
+
self.assertNotIn('src/new.js', self.box.guarded)
|
|
284
|
+
self.assertNotIn('src/new.js', self.box.known)
|
|
285
|
+
|
|
286
|
+
def test_the_temporary_file_of_a_save_leaves_no_line(self):
|
|
287
|
+
self.engine.refresh(self.box)
|
|
288
|
+
self.opened('src/sedAbC', flags=engine.O_CREAT | 1)
|
|
289
|
+
self.write('src/sedAbC', 'two')
|
|
290
|
+
os.rename(Path(self.folder.name) / 'src/sedAbC', Path(self.folder.name) / 'src/app.js')
|
|
291
|
+
self.engine.numbered_call(self.box, {'kind': 'syscall_return', 'sysno': 38, 'errno': 0, 'pid': 10, 'ppid': 1,
|
|
292
|
+
'process_start_ns': '10', 'timestamp_ns': str(time.time_ns()), 'cwd': '/workspace'})
|
|
293
|
+
self.assertEqual(self.looked('src/app.js', 'moved_to'), [('src/app.js', 'changed', 'project', 'call_10')])
|
|
294
|
+
self.assertEqual(len(self.looked('src/sedAbC', 'moved_from', final=True)), 1)
|
|
295
|
+
self.assertNotIn('src/sedAbC', self.box.guarded)
|
|
296
|
+
|
|
297
|
+
def test_a_file_or_a_folder_moved_in_is_kept(self):
|
|
298
|
+
self.engine.refresh(self.box)
|
|
299
|
+
self.write('src/moved.js', 'm')
|
|
300
|
+
self.engine.appeared(self.box, 'src/moved.js', False, False)
|
|
301
|
+
self.assertEqual(self.looked('src/moved.js', 'moved_to'), [('src/moved.js', 'created', 'project', None)])
|
|
302
|
+
self.write('lib/deep/a.js', 'a')
|
|
303
|
+
self.write('lib/node_modules/b.js', 'b')
|
|
304
|
+
self.engine.appeared(self.box, 'lib', True, False)
|
|
305
|
+
self.assertEqual({path for path in self.box.guarded if path.startswith('lib/')}, {'lib/deep/a.js'})
|
|
306
|
+
# A kept file under a new name is the same file: no second line for it.
|
|
307
|
+
os.rename(Path(self.folder.name) / 'src/app.js', Path(self.folder.name) / 'src/main.js')
|
|
308
|
+
self.engine.appeared(self.box, 'src/main.js', False, True)
|
|
309
|
+
self.assertEqual([fact for fact in self.looked('src/main.js', 'moved_to') if fact[0] == 'src/main.js'], [])
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def test_a_write_through_a_link_is_still_the_writers(self):
|
|
313
|
+
os.symlink('app.js', Path(self.folder.name) / 'src/alias.js')
|
|
314
|
+
self.engine.refresh(self.box)
|
|
315
|
+
self.assertNotIn('src/alias.js', self.box.guarded)
|
|
316
|
+
self.opened('src/alias.js', flags=engine.O_CREAT | engine.O_TRUNC | 1)
|
|
317
|
+
self.assertNotIn('src/alias.js', self.box.guarded)
|
|
318
|
+
self.write('src/app.js', 'through the link')
|
|
319
|
+
self.looked('src/app.js', 'modify', 'close_write')
|
|
320
|
+
(fact,) = self.engine.facts.values()
|
|
321
|
+
self.assertEqual((fact['call_id'], fact['certainty'], fact['basis']['via']), ('call_10', 'confirmed', 'src/alias.js'))
|
|
322
|
+
self.engine.facts.clear()
|
|
323
|
+
os.link(Path(self.folder.name) / 'src/app.js', Path(self.folder.name) / 'src/hard.js')
|
|
324
|
+
self.opened('src/hard.js', flags=engine.O_CREAT | 1)
|
|
325
|
+
self.write('src/hard.js', 'through the hard link')
|
|
326
|
+
self.looked('src/app.js', 'modify', 'close_write')
|
|
327
|
+
(fact,) = [fact for fact in self.engine.facts.values() if fact['path'] == 'src/app.js']
|
|
328
|
+
self.assertEqual((fact['call_id'], fact['basis']['via']), ('call_10', 'src/hard.js'))
|
|
329
|
+
|
|
330
|
+
|
|
214
331
|
if __name__ == '__main__':
|
|
215
332
|
unittest.main()
|