Fossil SCM

fossil-scm / test / crosslink.test
Blame History Raw 1667 lines
1
#
2
# Copyright (c) 2026 Dan Mestas
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the Simplified BSD License (also
6
# known as the "2-Clause License" or "FreeBSD License".)
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but without any warranty; without even the implied warranty of
10
# merchantability or fitness for a particular purpose.
11
#
12
############################################################################
13
#
14
# What the repository database shows after an artifact of each kind has
15
# been stored and crosslinked: manifest_crosslink() and the routines
16
# around it in src/manifest.c.
17
#
18
# Each artifact is written out here card by card, given its Z card, and
19
# stored with "fossil test-content-put --crosslink". That reaches cases
20
# the ordinary commands never produce: a reply to a forum post, an
21
# attachment whose target is not in the repository, a check-in whose
22
# baseline is missing.
23
#
24
25
# The first sections run at every level, and the rest need
26
# -assurance stress.
27
require_no_open_checkout
28
29
test_setup
30
31
set crosslinkSeq 0
32
33
# Write a file that holds the cards $body and the Z card for them, and
34
# return its name.
35
#
36
proc crosslink_file {body} {
37
global crosslinkSeq RESULT
38
set fn artifact-[incr crosslinkSeq].txt
39
set fd [open $fn wb]
40
puts -nonewline $fd $body
41
close $fd
42
fossil md5sum $fn
43
set sum [lindex $RESULT 0]
44
set fd [open $fn ab]
45
puts -nonewline $fd "Z $sum\n"
46
close $fd
47
return $fn
48
}
49
50
# Store the artifact whose cards, without the Z card, are $body. Return
51
# its hash, or an empty string if it was not stored. CODE and RESULT are
52
# those of test-content-put.
53
#
54
proc crosslink_put {body} {
55
global RESULT CODE
56
set fn [crosslink_file $body]
57
fossil test-content-put --crosslink $fn
58
set code $CODE
59
set result $RESULT
60
set hash ""
61
if {[regexp {inserted as record (\d+)} $result all rid]} {
62
fossil sql "SELECT uuid FROM blob WHERE rid=$rid"
63
set hash [string trim $RESULT ']
64
}
65
set CODE $code
66
set RESULT $result
67
return $hash
68
}
69
70
# A W card for the given text.
71
#
72
proc crosslink_w {text} {
73
return "W [string length $text]\n$text\n"
74
}
75
76
# Test NAME passes if ACTUAL matches the glob PATTERN.
77
#
78
proc crosslink_match {name actual pattern {constraints ""}} {
79
if {[string match $pattern $actual]} {set pattern $actual}
80
test_eq $name $actual $pattern $constraints
81
}
82
83
# The timeline text of the artifact with the given hash.
84
#
85
proc crosslink_event {hash} {
86
return [fossil_sql "SELECT type || ' ' || comment FROM event, blob\
87
WHERE objid=rid AND uuid='$hash'"]
88
}
89
90
set crosslinkNone [string repeat 0123456789 4]
91
set crosslinkNone2 [string repeat 9876543210 4]
92
93
###############################################################################
94
# Wiki pages: a new page, an edit, and an edit that empties the page.
95
96
set crosslinkW1 [crosslink_put "D 2026-01-01T10:00:00.000
97
L Crosslink\\sPage
98
U alice
99
[crosslink_w {first text}]"]
100
test crosslink-wiki-new {$CODE == 0 && $crosslinkW1 ne ""}
101
test_eq crosslink-wiki-new-event [crosslink_event $crosslinkW1] \
102
{w +Crosslink Page}
103
test_eq crosslink-wiki-new-tag [fossil_sql "SELECT value FROM tagxref, tag
104
WHERE tag.tagid=tagxref.tagid AND tagname='wiki-Crosslink Page'"] {10}
105
106
set crosslinkW2 [crosslink_put "D 2026-01-01T11:00:00.000
107
L Crosslink\\sPage
108
N text/x-markdown
109
P $crosslinkW1
110
U alice
111
[crosslink_w {second text}]"]
112
test_eq crosslink-wiki-edit-event [crosslink_event $crosslinkW2] \
113
{w :Crosslink Page}
114
test_eq crosslink-wiki-edit-plink [fossil_sql "SELECT count(*) FROM plink
115
WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkW2')
116
AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
117
118
set crosslinkW3 [crosslink_put "D 2026-01-01T12:00:00.000
119
L Crosslink\\sPage
120
P $crosslinkW2
121
U alice
122
[crosslink_w {}]"]
123
test_eq crosslink-wiki-empty-event [crosslink_event $crosslinkW3] \
124
{w -Crosslink Page}
125
126
# A parent that is not in the repository: the page still counts as an
127
# edit.
128
set crosslinkW4 [crosslink_put "D 2026-01-01T12:30:00.000
129
L Orphan
130
P $crosslinkNone
131
U alice
132
[crosslink_w {text}]"]
133
test_eq crosslink-wiki-missing-parent [crosslink_event $crosslinkW4] \
134
{w :Orphan}
135
136
###############################################################################
137
# Tech notes: a note, a later version of it, and an earlier version that
138
# arrives last.
139
140
set crosslinkEid [string repeat ab 20]
141
set crosslinkE1 [crosslink_put "C First\\snote
142
D 2026-01-02T10:00:00.000
143
E 2026-01-02T09:00:00 $crosslinkEid
144
T +bgcolor * #abcdef
145
T +sym-noted *
146
U alice
147
[crosslink_w {note}]"]
148
test crosslink-technote-new {$CODE == 0 && $crosslinkE1 ne ""}
149
test_eq crosslink-technote-new-event [fossil_sql "SELECT type, comment,
150
bgcolor FROM event, blob WHERE objid=rid AND uuid='$crosslinkE1'"] \
151
{e|First note|#abcdef}
152
153
set crosslinkE2 [crosslink_put "C Second\\snote
154
D 2026-01-02T11:00:00.000
155
E 2026-01-02T09:00:00 $crosslinkEid
156
P $crosslinkE1
157
U alice
158
[crosslink_w {note2}]"]
159
test_eq crosslink-technote-edit-only-latest [fossil_sql "SELECT comment
160
FROM event WHERE type='e'"] {Second note}
161
162
crosslink_put "C Earlier\\snote
163
D 2026-01-02T08:00:00.000
164
E 2026-01-02T09:00:00 $crosslinkEid
165
U alice
166
[crosslink_w {note0}]"
167
test_eq crosslink-technote-older-arrives-last [fossil_sql "SELECT comment
168
FROM event WHERE type='e'"] {Second note}
169
170
###############################################################################
171
# Tickets: a new ticket, a change of status with other fields, a change
172
# without the status, and one with a single field.
173
174
set crosslinkTkt [string repeat cd 20]
175
set crosslinkT1 [crosslink_put "D 2026-01-03T10:00:00.000
176
J status Open
177
J title Crosslink\\sticket
178
K $crosslinkTkt
179
U alice
180
"]
181
test crosslink-ticket-new {$CODE == 0 && $crosslinkT1 ne ""}
182
crosslink_match crosslink-ticket-new-event [crosslink_event $crosslinkT1] \
183
{t New ticket *Crosslink ticket*}
184
test_eq crosslink-ticket-new-row [fossil_sql "SELECT status, title
185
FROM ticket WHERE tkt_uuid='$crosslinkTkt'"] {Open|Crosslink ticket}
186
187
set crosslinkT2 [crosslink_put "D 2026-01-03T11:00:00.000
188
J priority High
189
J severity Minor
190
J status Fixed
191
K $crosslinkTkt
192
U alice
193
"]
194
crosslink_match crosslink-ticket-status-plus-two \
195
[crosslink_event $crosslinkT2] \
196
{t Fixed ticket * plus 2 other changes}
197
198
set crosslinkT3 [crosslink_put "D 2026-01-03T12:00:00.000
199
J priority Low
200
J status Closed
201
K $crosslinkTkt
202
U alice
203
"]
204
crosslink_match crosslink-ticket-status-plus-one \
205
[crosslink_event $crosslinkT3] \
206
{t Closed ticket * plus 1 other change}
207
208
set crosslinkT4 [crosslink_put "D 2026-01-03T13:00:00.000
209
J priority Medium
210
J severity Severe
211
K $crosslinkTkt
212
U alice
213
"]
214
crosslink_match crosslink-ticket-no-status-two [crosslink_event $crosslinkT4] \
215
{t Ticket * status still Closed with 2 other changes}
216
217
set crosslinkT5 [crosslink_put "D 2026-01-03T14:00:00.000
218
J +comment more\\stext
219
K $crosslinkTkt
220
U alice
221
"]
222
crosslink_match crosslink-ticket-no-status-one [crosslink_event $crosslinkT5] \
223
{t Ticket * status still Closed with 1 other change}
224
225
set crosslinkT6 [crosslink_put "D 2026-01-03T15:00:00.000
226
J status Verified
227
K $crosslinkTkt
228
U alice
229
"]
230
crosslink_match crosslink-ticket-status-only [crosslink_event $crosslinkT6] \
231
{t Verified ticket *}
232
test {crosslink-ticket-status-only-no-plus} \
233
{![string match *plus* [crosslink_event $crosslinkT6]]}
234
test_eq crosslink-ticket-events [fossil_sql "SELECT count(*) FROM event
235
WHERE type='t'"] 6
236
237
###############################################################################
238
# Forum posts: a thread, an edit of its first post, a reply, an edit of
239
# the reply, a deleted reply, and an older edit of the first post that
240
# arrives last.
241
242
set crosslinkFtext "See \[[string range $crosslinkW1 0 15]\]."
243
set crosslinkF1 [crosslink_put "D 2026-01-04T10:00:01.000
244
H Crosslink\\sthread
245
U alice
246
[crosslink_w $crosslinkFtext]"]
247
test crosslink-forum-post {$CODE == 0 && $crosslinkF1 ne ""}
248
test_eq crosslink-forum-post-event [crosslink_event $crosslinkF1] \
249
{f Post: Crosslink thread}
250
test_eq crosslink-forum-post-backlink [fossil_sql "SELECT count(*)
251
FROM backlink WHERE srctype=4
252
AND srcid=(SELECT rid FROM blob WHERE uuid='$crosslinkF1')"] 1
253
254
set crosslinkF2 [crosslink_put "D 2026-01-04T11:00:00.000
255
G $crosslinkF1
256
I $crosslinkF1
257
N text/x-markdown
258
U bob
259
[crosslink_w {reply}]"]
260
test_eq crosslink-forum-reply-event [crosslink_event $crosslinkF2] \
261
{f Reply: Crosslink thread}
262
test_eq crosslink-forum-reply-row [fossil_sql "SELECT
263
froot=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'),
264
firt=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'), fprev IS NULL
265
FROM forumpost WHERE fpid=(SELECT rid FROM blob
266
WHERE uuid='$crosslinkF2')"] {1|1|1}
267
268
set crosslinkF3 [crosslink_put "D 2026-01-04T12:00:00.000
269
G $crosslinkF1
270
I $crosslinkF1
271
P $crosslinkF2
272
U bob
273
[crosslink_w {reply2}]"]
274
test_eq crosslink-forum-reply-edit-event [crosslink_event $crosslinkF3] \
275
{f Edit reply: Crosslink thread}
276
277
set crosslinkF4 [crosslink_put "D 2026-01-04T13:00:00.000
278
G $crosslinkF1
279
I $crosslinkF1
280
P $crosslinkF3
281
U bob
282
[crosslink_w {}]"]
283
test_eq crosslink-forum-reply-delete-event [crosslink_event $crosslinkF4] \
284
{f Delete reply: Crosslink thread}
285
286
set crosslinkF5 [crosslink_put "D 2026-01-04T14:00:00.000
287
G $crosslinkF1
288
H New\\stitle
289
P $crosslinkF1
290
U alice
291
[crosslink_w {text}]"]
292
test_eq crosslink-forum-edit-event [crosslink_event $crosslinkF5] \
293
{f Edit: New title}
294
test_eq crosslink-forum-edit-retitles-thread [crosslink_event $crosslinkF2] \
295
{f Reply: New title}
296
297
# An edit of the first post dated before the one above does not change
298
# the title of the thread.
299
set crosslinkF6 [crosslink_put "D 2026-01-04T13:30:00.000
300
G $crosslinkF1
301
H Older\\stitle
302
P $crosslinkF1
303
U alice
304
[crosslink_w {text}]"]
305
test_eq crosslink-forum-older-edit-event [crosslink_event $crosslinkF6] \
306
{f Edit: Older title}
307
test_eq crosslink-forum-older-edit-keeps-title [crosslink_event $crosslinkF2] \
308
{f Reply: New title}
309
310
# A first post with its title removed.
311
set crosslinkF7 [crosslink_put "D 2026-01-04T15:00:00.000
312
G $crosslinkF1
313
P $crosslinkF5
314
U alice
315
[crosslink_w {}]"]
316
test_eq crosslink-forum-deleted-thread [crosslink_event $crosslinkF7] \
317
{f Edit: (Deleted)}
318
319
# A reply to a thread whose first post is not in the repository.
320
set crosslinkF8 [crosslink_put "D 2026-01-04T16:00:00.000
321
G $crosslinkNone
322
I $crosslinkNone
323
U bob
324
[crosslink_w {reply}]"]
325
test_eq crosslink-forum-reply-unknown-thread [crosslink_event $crosslinkF8] \
326
{f Reply: <i>Unknown</i>}
327
328
if {[test_assurance] ne "stress"} {
329
test_skip "the tests after the first sections need -assurance stress"
330
}
331
332
###############################################################################
333
# Attachments, added to and deleted from each kind of target.
334
335
set crosslinkSrc [string repeat ef 20]
336
foreach {crosslinkKind crosslinkTarget crosslinkType crosslinkAdd
337
crosslinkDel} [list \
338
wiki Crosslink\\sPage w {*to wiki page \[Crosslink Page\]*} \
339
{*from wiki page \[Crosslink Page\]*} \
340
technote $crosslinkEid e {*to tech note *} \
341
{"file.txt" from tech note \[/technote/*\]} \
342
ticket $crosslinkTkt t {*to ticket *} {*from ticket *} \
343
forum $crosslinkF1 f {*to forum post *} {*from forum post *} \
344
unknown $crosslinkNone2 a {*to \[/artifact/*} \
345
{"file.txt" from \[/artifact/*\]} \
346
] {
347
set crosslinkA [crosslink_put "A file.txt $crosslinkTarget $crosslinkSrc
348
C A\\scomment
349
D 2026-01-05T10:00:00.000
350
U alice
351
"]
352
test crosslink-attach-$crosslinkKind-add {$CODE == 0 && $crosslinkA ne ""}
353
set crosslinkEv [crosslink_event $crosslinkA]
354
crosslink_match crosslink-attach-$crosslinkKind-add-event $crosslinkEv \
355
"$crosslinkType Add attachment $crosslinkAdd"
356
set crosslinkA [crosslink_put "A file.txt $crosslinkTarget
357
D 2026-01-05T11:00:00.000
358
U alice
359
"]
360
set crosslinkEv [crosslink_event $crosslinkA]
361
crosslink_match crosslink-attach-$crosslinkKind-delete-event $crosslinkEv \
362
"$crosslinkType Delete attachment $crosslinkDel"
363
test_eq crosslink-attach-$crosslinkKind-latest [fossil_sql "SELECT
364
group_concat(isLatest,'') FROM (SELECT isLatest FROM attachment
365
WHERE target='[string map {\\s { }} $crosslinkTarget]' ORDER BY mtime)"] \
366
{01}
367
}
368
test_eq crosslink-attach-rows [fossil_sql \
369
"SELECT count(*) FROM attachment"] 10
370
371
# A later change to a ticket or a tech note rewrites the timeline text of
372
# its attachments.
373
crosslink_put "D 2026-01-05T12:00:00.000
374
J status Open
375
K $crosslinkTkt
376
U alice
377
"
378
test_eq crosslink-ticket-rewrites-attachments [fossil_sql "SELECT count(*)
379
FROM event WHERE type='t' AND (comment LIKE 'Add attachment % to ticket %'
380
OR comment LIKE 'Delete attachment % from ticket %')"] 2
381
crosslink_put "C Third\\snote
382
D 2026-01-05T12:00:00.000
383
E 2026-01-02T09:00:00 $crosslinkEid
384
P $crosslinkE2
385
U alice
386
[crosslink_w {note3}]"
387
test_eq crosslink-technote-rewrites-attachments [fossil_sql "SELECT
388
count(*) FROM event WHERE type='e'
389
AND (comment LIKE 'Add attachment % to tech note %'
390
OR comment LIKE 'Delete attachment % from tech note %')"] 2
391
392
###############################################################################
393
# Check-ins made by hand, and the tags put on them.
394
395
write_file a.txt "a\n"
396
write_file b.txt "b\n"
397
fossil add a.txt b.txt
398
fossil commit -m "crosslink-c1" --no-warnings
399
set crosslinkC1 [fossil_sql "SELECT uuid FROM blob, event
400
WHERE rid=objid AND comment='crosslink-c1'"]
401
set crosslinkC1 [string trim $crosslinkC1 ']
402
set crosslinkFa [string trim [fossil_sql "SELECT uuid FROM blob, mlink,
403
filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
404
AND name='a.txt'"] ']
405
set crosslinkFb [string trim [fossil_sql "SELECT uuid FROM blob, mlink,
406
filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
407
AND name='b.txt'"] ']
408
test crosslink-setup-checkin \
409
{$crosslinkC1 ne "" && $crosslinkFa ne "" && $crosslinkFb ne ""}
410
411
# Every kind of tag that has its own wording in the timeline.
412
foreach {crosslinkName crosslinkCard crosslinkWant} [list \
413
branch "*branch * other" {*Move to branch*other*} \
414
bgcolor-prop "*bgcolor * #112233" \
415
{*Change branch background color to "#112233".*} \
416
bgcolor "+bgcolor * #445566" \
417
{*Change background color to "#445566".*} \
418
bgcolor-off "-bgcolor *" {*Cancel background color.*} \
419
comment "+comment * new\\stext" {*Edit check-in comment.*} \
420
user "+user * carol" {*Change user to "carol".*} \
421
date "+date * 2026-01-06\\s09:00:00" \
422
{*Timestamp 2026-01-06 09:00:00.*} \
423
sym-add "+sym-one *" {*Add tag "one".*} \
424
sym-add-note "+sym-two * a\\snote" \
425
{*Add tag "two" with note "a note".*} \
426
sym-prop "*sym-three *" {*Add propagating tag "three".*} \
427
sym-cancel "-sym-one *" {*Cancel tag "one".*} \
428
closed "+closed *" {*Mark "Closed".*} \
429
closed-off "-closed *" {*Remove the "Closed" mark.*} \
430
other-add "+thing *" {*Add "thing".*} \
431
other-value "+thing2 * val" {*Add "thing2" with value "val".*} \
432
other-prop "*thing3 *" {*Add propagating "thing3".*} \
433
other-cancel "-thing *" {*Cancel "thing".*} \
434
] {
435
set crosslinkCard [string map [list " * " " $crosslinkC1 "] $crosslinkCard]
436
if {[string match "* \\*" $crosslinkCard]} {
437
set crosslinkCard "[string range $crosslinkCard 0 end-1]$crosslinkC1"
438
}
439
set crosslinkG [crosslink_put "D 2026-01-06T10:00:[format %02d \
440
[incr crosslinkSeq 0]].000
441
T $crosslinkCard
442
U alice
443
"]
444
test crosslink-tag-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
445
crosslink_match crosslink-tag-$crosslinkName-event \
446
[crosslink_event $crosslinkG] "g Edit *:$crosslinkWant"
447
}
448
test_eq crosslink-tag-comment-applied [fossil_sql "SELECT ecomment, euser
449
FROM event WHERE objid=(SELECT rid FROM blob WHERE uuid='$crosslinkC1')"] \
450
{new text|carol}
451
452
# A branch move with its symbolic tags says only that the branch moved.
453
set crosslinkG [crosslink_put "D 2026-01-06T11:00:00.000
454
T *branch $crosslinkC1 moved
455
T *sym-moved $crosslinkC1
456
T -sym-other $crosslinkC1
457
U alice
458
"]
459
crosslink_match crosslink-tag-branch-move-quiet [crosslink_event $crosslinkG] \
460
{g Edit *: Move to branch *moved*}
461
test crosslink-tag-branch-move-no-sym \
462
{![string match *tag* [crosslink_event $crosslinkG]]}
463
464
# Tags for two check-ins in one artifact are listed under each.
465
set crosslinkTwo [lsort [list $crosslinkC1 $crosslinkW1]]
466
set crosslinkG [crosslink_put "D 2026-01-06T11:15:00.000
467
T +sym-both [lindex $crosslinkTwo 0]
468
T +sym-both [lindex $crosslinkTwo 1]
469
U alice
470
"]
471
crosslink_match crosslink-tag-two-targets [crosslink_event $crosslinkG] \
472
{g Edit *: Add tag "both". Edit *: Add tag "both".}
473
474
# A tag on an artifact that is not in the repository is recorded against
475
# a phantom.
476
set crosslinkG [crosslink_put "D 2026-01-06T11:30:00.000
477
T +sym-far $crosslinkNone
478
U alice
479
"]
480
crosslink_match crosslink-tag-on-missing [crosslink_event $crosslinkG] \
481
{g Edit *: Add tag "far".}
482
483
###############################################################################
484
# A check-in with a second parent, a cherrypick, a symbolic link, an
485
# executable and a renamed file.
486
487
set crosslinkM1 [crosslink_put "C crosslink-c2
488
D 2026-01-07T10:00:00.000
489
F a.txt $crosslinkFa x
490
F c.txt $crosslinkFb w b.txt
491
F l.txt $crosslinkFa l
492
P $crosslinkC1
493
Q +$crosslinkC1
494
Q -$crosslinkC1 $crosslinkC1
495
T +sym-made-by-hand *
496
U alice
497
"]
498
test crosslink-checkin {$CODE == 0 && $crosslinkM1 ne ""}
499
test_eq crosslink-checkin-event [crosslink_event $crosslinkM1] \
500
{ci crosslink-c2}
501
test_eq crosslink-checkin-mlink [fossil_sql "SELECT group_concat(
502
name || ':' || mperm || ':' || (pfnid>0), ' ') FROM (SELECT name, mperm,
503
pfnid FROM mlink, filename WHERE mlink.fnid=filename.fnid
504
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')
505
ORDER BY name)"] {a.txt:1:0 b.txt:0:0 c.txt:0:1 l.txt:2:0}
506
test_eq crosslink-checkin-cherrypick [fossil_sql "SELECT count(*)
507
FROM cherrypick WHERE childid=(SELECT rid FROM blob
508
WHERE uuid='$crosslinkM1')"] 1
509
510
# A delta manifest, a second one on the same baseline, and an ordinary
511
# check-in after them. The second does not repeat the removal of a.txt,
512
# so the file is back.
513
set crosslinkM2 [crosslink_put "B $crosslinkM1
514
C crosslink-c3
515
D 2026-01-07T11:00:00.000
516
F a.txt
517
F d.txt $crosslinkFb
518
P $crosslinkM1
519
U alice
520
"]
521
test crosslink-delta-checkin {$CODE == 0 && $crosslinkM2 ne ""}
522
test_eq crosslink-delta-checkin-mlink [fossil_sql "SELECT group_concat(
523
name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
524
WHERE mlink.fnid=filename.fnid
525
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM2')
526
ORDER BY name)"] {a.txt:0 d.txt:1}
527
test_eq crosslink-delta-seen [fossil_sql "SELECT value FROM config
528
WHERE name='seen-delta-manifest'"] 1
529
530
set crosslinkM3 [crosslink_put "B $crosslinkM1
531
C crosslink-c4
532
D 2026-01-07T12:00:00.000
533
F c.txt
534
F d.txt $crosslinkFa
535
F e.txt $crosslinkFa
536
P $crosslinkM2
537
U alice
538
"]
539
test_eq crosslink-delta-to-delta-mlink [fossil_sql "SELECT group_concat(
540
name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
541
WHERE mlink.fnid=filename.fnid
542
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM3')
543
ORDER BY name)"] {a.txt:1 c.txt:0 d.txt:1 e.txt:1}
544
545
set crosslinkM4 [crosslink_put "C crosslink-c5
546
D 2026-01-07T13:00:00.000
547
F a.txt $crosslinkFa
548
F e.txt $crosslinkFb
549
P $crosslinkM3
550
U alice
551
"]
552
test_eq crosslink-full-after-delta-mlink [fossil_sql "SELECT group_concat(
553
name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
554
WHERE mlink.fnid=filename.fnid
555
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')
556
ORDER BY name)"] {a.txt:1 d.txt:0 e.txt:1 l.txt:0}
557
558
# The files of each of them can be listed and checked out.
559
foreach crosslinkCi [list $crosslinkM1 $crosslinkM2 $crosslinkM3 $crosslinkM4] {
560
fossil ls -r $crosslinkCi
561
test crosslink-ls-[string range $crosslinkCi 0 7] {$CODE == 0}
562
}
563
fossil ls -r $crosslinkM3
564
test_eq crosslink-ls-delta [normalize_result] "a.txt\nd.txt\ne.txt\nl.txt"
565
566
# A file that a delta manifest removes cannot be read from that check-in,
567
# and one that it leaves alone comes from the baseline.
568
fossil cat a.txt -r $crosslinkM2 -expectError
569
test crosslink-cat-removed-by-delta {$CODE != 0}
570
fossil cat l.txt -r $crosslinkM2
571
test_eq crosslink-cat-from-baseline [normalize_result] a
572
573
# A check-in that picks a change from a check-in that is not in the
574
# repository.
575
set crosslinkM5 [crosslink_put "C crosslink-c6
576
D 2026-01-07T13:30:00.000
577
F a.txt $crosslinkFa
578
P $crosslinkM4
579
Q +$crosslinkNone
580
U alice
581
"]
582
test_eq crosslink-cherrypick-of-missing [crosslink_event $crosslinkM5] \
583
{ci crosslink-c6}
584
585
# A check-in whose baseline is not in the repository is stored but not
586
# shown, and so is anything that is not an artifact.
587
set crosslinkBad [crosslink_put "B $crosslinkNone
588
C crosslink-no-baseline
589
D 2026-01-07T14:00:00.000
590
F a.txt $crosslinkFa
591
P $crosslinkM1
592
U alice
593
"]
594
test crosslink-missing-baseline {$CODE == 0 && $crosslinkBad ne ""}
595
test_eq crosslink-missing-baseline-no-event [fossil_sql "SELECT count(*)
596
FROM event WHERE comment='crosslink-no-baseline'"] 0
597
598
# A check-in whose parent is that one is still shown; its files cannot be
599
# compared with the parent's.
600
set crosslinkM6 [crosslink_put "C crosslink-child-of-no-baseline
601
D 2026-01-07T14:30:00.000
602
F a.txt $crosslinkFa
603
P $crosslinkBad
604
U alice
605
"]
606
test_eq crosslink-child-of-missing-baseline [crosslink_event $crosslinkM6] \
607
{ci crosslink-child-of-no-baseline}
608
609
write_file not-an-artifact.txt "This is a file.\n"
610
set crosslinkEvents [fossil_sql "SELECT count(*) FROM event"]
611
fossil test-content-put --crosslink not-an-artifact.txt
612
test crosslink-not-an-artifact {$CODE == 0}
613
test_eq crosslink-not-an-artifact-no-event \
614
[fossil_sql "SELECT count(*) FROM event"] $crosslinkEvents
615
616
###############################################################################
617
# The "parent" tag gives a check-in other parents; a bad value is ignored.
618
619
fossil reparent $crosslinkM4 $crosslinkC1 $crosslinkM2
620
test crosslink-reparent {$CODE == 0}
621
test_eq crosslink-reparent-plink [fossil_sql "SELECT count(*) FROM plink
622
WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')"] 2
623
test_eq crosslink-reparent-primary [fossil_sql "SELECT uuid FROM plink,
624
blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
625
WHERE uuid='$crosslinkM4')"] $crosslinkC1
626
627
crosslink_put "D 2026-01-08T10:00:00.000
628
T +parent $crosslinkM3 not-a-hash
629
U alice
630
"
631
test crosslink-reparent-bad-value {$CODE == 0}
632
test_eq crosslink-reparent-bad-value-ignored [fossil_sql "SELECT uuid
633
FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
634
WHERE uuid='$crosslinkM3')"] $crosslinkM2
635
636
# A value of good hashes followed by a short word is ignored as a whole,
637
# both when the tag arrives and when a rebuild reads it again.
638
set crosslinkI 0
639
foreach {crosslinkName crosslinkValue} [list \
640
two-sha3-short "$crosslinkM1\\s$crosslinkM2\\sx" \
641
one-sha3-short "$crosslinkM1\\sx" \
642
one-sha1-short "[string repeat a 40]\\sxxxxx" \
643
] {
644
set crosslinkG [crosslink_put "D 2026-01-08T10:0[incr crosslinkI]:00.000
645
T +parent $crosslinkM3 $crosslinkValue
646
U alice
647
"]
648
test crosslink-reparent-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
649
test_eq crosslink-reparent-$crosslinkName-ignored [fossil_sql "SELECT
650
uuid FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid
651
FROM blob WHERE uuid='$crosslinkM3')"] $crosslinkM2
652
}
653
fossil rebuild
654
test crosslink-reparent-short-rebuild {$CODE == 0}
655
test_eq crosslink-reparent-short-rebuild-ignored [fossil_sql "SELECT uuid
656
FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
657
WHERE uuid='$crosslinkM3')"] $crosslinkM2
658
659
###############################################################################
660
# A cluster removes its members from the list of unclustered artifacts.
661
662
set crosslinkBefore [fossil_sql "SELECT count(*) FROM unclustered"]
663
set crosslinkCl ""
664
foreach crosslinkHash [lsort [list $crosslinkC1 $crosslinkM1 $crosslinkNone2]] {
665
append crosslinkCl "M $crosslinkHash\n"
666
}
667
set crosslinkCl [crosslink_put $crosslinkCl]
668
test crosslink-cluster {$CODE == 0 && $crosslinkCl ne ""}
669
test_eq crosslink-cluster-tag [fossil_sql "SELECT count(*) FROM tagxref
670
WHERE tagid=(SELECT tagid FROM tag WHERE tagname='cluster')
671
AND rid=(SELECT rid FROM blob WHERE uuid='$crosslinkCl')"] 1
672
test crosslink-cluster-unclustered \
673
{[fossil_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1}
674
675
###############################################################################
676
# The JSON form of each kind of artifact.
677
678
foreach {crosslinkKind crosslinkHash crosslinkWant} [list \
679
wiki $crosslinkW2 \
680
{*"type":"wiki"*"L":"Crosslink Page"*"N":"text/x-markdown"*"P":*"W":*} \
681
technote $crosslinkE1 \
682
{*"type":"technote"*"C":"First note"*"E":*"T":*"W":*} \
683
ticket $crosslinkT5 {*"type":"ticket"*"J":*"append":true*"K":*} \
684
ticket2 $crosslinkT2 {*"type":"ticket"*"J":*"append":false*} \
685
forum $crosslinkF3 {*"type":"forumpost"*"G":*"I":*"P":*"W":*} \
686
forum2 $crosslinkF5 {*"type":"forumpost"*"H":"New title"*} \
687
attachment "" {*"type":"attachment"*"A":*} \
688
tag $crosslinkG {*"type":"tag"*"T":*} \
689
checkin $crosslinkM1 \
690
{*"type":"checkin"*"C":"crosslink-c2"*"F":*"perm":"x"*"P":*"Q":*"T":*"U":"alice"*} \
691
delta $crosslinkM2 {*"type":"checkin"*"B":*"F":*} \
692
cluster $crosslinkCl {*"type":"cluster"*"M":*} \
693
] {
694
if {$crosslinkHash eq ""} {
695
set crosslinkHash [string trim [fossil_sql "SELECT uuid FROM blob,
696
attachment WHERE rid=attachid ORDER BY rid LIMIT 1"] ']
697
}
698
fossil test-artifact-to-json $crosslinkHash
699
test crosslink-json-$crosslinkKind {$CODE == 0}
700
crosslink_match crosslink-json-$crosslinkKind-text $RESULT $crosslinkWant
701
}
702
# Every artifact that the repository shows in its timeline has a JSON
703
# form.
704
fossil sql "SELECT uuid FROM blob WHERE rid IN (SELECT objid FROM event)"
705
set crosslinkAll [string map {' {}} $RESULT]
706
fossil test-artifact-to-json {*}$crosslinkAll
707
test crosslink-json-every-artifact {$CODE == 0 && [llength $crosslinkAll] > 30}
708
709
fossil test-artifact-to-json --pretty $crosslinkW1 $crosslinkT1
710
test crosslink-json-pretty {$CODE == 0}
711
crosslink_match crosslink-json-pretty-text $RESULT "*\"type\": \"wiki\"*"
712
fossil test-artifact-to-json $crosslinkFa no-such-name -expectError
713
test crosslink-json-not-artifact {$CODE != 0}
714
715
# The same through SQL: by hash, by record number, and with arguments
716
# that name nothing.
717
crosslink_match crosslink-json-sql-name [fossil_sql \
718
"SELECT artifact_to_json('$crosslinkW1')"] {*"type":"wiki"*}
719
crosslink_match crosslink-json-sql-rid [fossil_sql "SELECT artifact_to_json(
720
(SELECT rid FROM blob WHERE uuid='$crosslinkW1'))"] {*"type":"wiki"*}
721
test_eq crosslink-json-sql-data [fossil_sql \
722
"SELECT artifact_to_json('$crosslinkFa') IS NULL"] 1
723
fossil sql "SELECT artifact_to_json(NULL)" -expectError
724
test crosslink-json-sql-null {$CODE != 0}
725
crosslink_match crosslink-json-sql-null-message $RESULT \
726
{*Expecting one argument*}
727
fossil sql "SELECT artifact_to_json(1.5)" -expectError
728
test crosslink-json-sql-float {$CODE != 0}
729
test_eq crosslink-json-sql-zero [fossil_sql \
730
"SELECT artifact_to_json(0) IS NULL"] 1
731
fossil sql "SELECT artifact_to_json()" -expectError
732
test crosslink-json-sql-no-argument {$CODE != 0}
733
734
###############################################################################
735
# What the parser refuses, and the reason it gives.
736
737
set crosslinkH40 [string repeat ab 20]
738
foreach {crosslinkName crosslinkBody crosslinkWant} [list \
739
cards-out-of-order "U alice\nD 2026-02-01T10:00:00.000\n" \
740
{*cards not in lexicographical order*} \
741
bad-card-type "D 2026-02-01T10:00:00.000\na b\n" \
742
{*bad card type*} \
743
first-line-not-a-card "1 x\nD 2026-02-01T10:00:00.000\n" \
744
{*line 1 not recognized*} \
745
control-tags-itself "D 2026-02-01T10:00:00.000\nT +sym-x *\nU alice\n" \
746
{*self-referential T-card in control artifact*} \
747
technote-tags-another \
748
[join [list \
749
"D 2026-02-01T10:00:00.000\n" \
750
"E 2026-02-01T09:00:00 $crosslinkH40\n" \
751
"T +sym-x $crosslinkH40\nU alice\nW 1\nx\n"] ""] \
752
{*non-self-referential T-card in technote*} \
753
technote-propagating-tag \
754
[join [list \
755
"D 2026-02-01T10:00:00.000\n" \
756
"E 2026-02-01T09:00:00 $crosslinkH40\nT *sym-x *\nU alice\n" \
757
"W 1\nx\n"] ""] \
758
{*T-card with '\*' or '-' in technote*} \
759
forum-title-on-reply \
760
[join [list \
761
"D 2026-02-01T10:00:00.000\nG $crosslinkH40\nH title\n" \
762
"I $crosslinkH40\nU alice\nW 1\nx\n"] ""] \
763
{*cannot have I-card and H-card in a forum post*} \
764
forum-two-parents \
765
[join [list \
766
"D 2026-02-01T10:00:00.000\nG $crosslinkH40\n" \
767
"P $crosslinkH40 $crosslinkNone\nU alice\nW 1\nx\n"] ""] \
768
{*too many arguments to P-card*} \
769
] {
770
fossil test-parse-manifest [crosslink_file $crosslinkBody]
771
test crosslink-refuse-$crosslinkName {$CODE == 0}
772
crosslink_match crosslink-refuse-$crosslinkName-reason $RESULT \
773
"*ERROR:$crosslinkWant"
774
}
775
776
# A file that does not end in a newline, an empty one, and one whose Z
777
# card does not match.
778
write_file refuse-no-newline.txt "D 2026-02-01T10:00:00.000\nU alice"
779
fossil test-parse-manifest refuse-no-newline.txt
780
crosslink_match crosslink-refuse-no-newline $RESULT {*ERROR:*not terminated*}
781
write_file refuse-empty.txt ""
782
fossil test-parse-manifest refuse-empty.txt
783
crosslink_match crosslink-refuse-empty $RESULT {*ERROR:*zero-length*}
784
write_file refuse-checksum.txt \
785
"D 2026-02-01T10:00:00.000\nU alice\nZ [string repeat 0 32]\n"
786
fossil test-parse-manifest refuse-checksum.txt
787
crosslink_match crosslink-refuse-checksum $RESULT \
788
{*ERROR:*incorrect Z-card cksum*}
789
790
# Files without a comment are still a check-in.
791
fossil test-parse-manifest [crosslink_file \
792
"D 2026-02-01T10:00:00.000\nF a.txt $crosslinkH40\nU alice\n"]
793
crosslink_match crosslink-files-without-comment $RESULT \
794
{*manifest_parse() worked*}
795
796
# A tech note may have its N card after its P card, as old versions of
797
# Fossil wrote it. A file with a reserved name in a check-in is left out.
798
fossil test-parse-manifest [crosslink_file \
799
[join [list \
800
"D 2026-02-01T10:00:00.000\n" \
801
"E 2026-02-01T09:00:00 $crosslinkH40\nP $crosslinkH40\n" \
802
"N text/plain\nU alice\nW 1\nx\n"] ""]]
803
crosslink_match crosslink-technote-n-after-p $RESULT {*manifest_parse() worked*}
804
fossil test-parse-manifest [crosslink_file \
805
[join [list \
806
"C reserved\nD 2026-02-01T10:00:00.000\n" \
807
"F _FOSSIL_ $crosslinkH40\nF a.txt $crosslinkH40\nU alice\n"] ""]] 2
808
crosslink_match crosslink-reserved-name-ignored $RESULT \
809
{*manifest_parse() worked*}
810
811
# Content that is not an artifact but begins like one. The quick check
812
# and the parser must agree about each.
813
foreach {crosslinkName crosslinkText} [list \
814
digit-first "1 x and some more text\nD x\n" \
815
no-space "AB and some more text\nD x\n" \
816
no-newline "D 2026-02-01T10:00:00.000 and no end of line" \
817
one-card "D x\n" \
818
short "D\n" \
819
second-lower "D 2026-02-01T10:00:00.000\nlower case\n" \
820
second-earlier "D 2026-02-01T10:00:00.000\nC comment\nmore text here\n" \
821
second-no-space "D 2026-02-01T10:00:00.000\nUalice and more\n" \
822
late-letter "N text/plain\nU alice and more\n" \
823
] {
824
write_file wf-$crosslinkName.txt $crosslinkText
825
fossil test-content-put wf-$crosslinkName.txt
826
test crosslink-not-wellformed-$crosslinkName {$CODE == 0}
827
}
828
fossil test-parse-all-blobs --wellformed
829
crosslink_match crosslink-wellformed-agrees $RESULT {*tests with 0 errors*}
830
831
# A name that is not a check-in, where one is needed.
832
fossil ls -r $crosslinkW1 -expectError
833
test crosslink-wiki-is-not-a-checkin {$CODE != 0}
834
crosslink_match crosslink-wiki-is-not-a-checkin-message $RESULT \
835
{*not a valid check-in*}
836
837
# Wiki text and a tech note that begin with blank space, and crosslinking
838
# with SQL tracing on.
839
crosslink_put "D 2026-02-02T10:00:00.000
840
L Indented
841
U alice
842
[crosslink_w "\n\n indented"]"
843
test_eq crosslink-wiki-leading-space-length [fossil_sql "SELECT value
844
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
845
AND tagname='wiki-Indented'"] 8
846
crosslink_put "C Indented\\snote
847
D 2026-02-02T11:00:00.000
848
E 2026-02-02T09:00:00 [string repeat 12 20]
849
U alice
850
[crosslink_w "\n note"]"
851
test_eq crosslink-technote-leading-space-length [fossil_sql "SELECT value
852
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
853
AND tagname='event-[string repeat 12 20]'"] 4
854
fossil_raw test-crosslink $crosslinkW1 --sqltrace
855
test crosslink-sqltrace {$CODE == 0}
856
crosslink_match crosslink-sqltrace-text $RESULT {*-- manifest_crosslink(*}
857
858
###############################################################################
859
# The commands that parse artifacts again.
860
861
fossil artifact $crosslinkM1 checkin.txt
862
fossil test-parse-manifest checkin.txt
863
test crosslink-parse-manifest {$CODE == 0}
864
crosslink_match crosslink-parse-manifest-text $RESULT {*is ok*}
865
fossil test-parse-manifest checkin.txt 5
866
test crosslink-parse-manifest-repeat {$CODE == 0}
867
fossil test-parse-manifest checkin.txt 2
868
crosslink_match crosslink-parse-manifest-twice $RESULT \
869
{*manifest_parse() worked*manifest_parse() worked*}
870
fossil test-parse-manifest not-an-artifact.txt 3
871
crosslink_match crosslink-parse-manifest-bad $RESULT {*contains errors*}
872
fossil test-parse-manifest -expectError
873
test crosslink-parse-manifest-usage {$CODE != 0}
874
875
fossil test-parse-all-blobs
876
test crosslink-parse-all {$CODE == 0}
877
crosslink_match crosslink-parse-all-text $RESULT {*tests with 0 errors*}
878
fossil test-parse-all-blobs --limit 3
879
crosslink_match crosslink-parse-all-limit $RESULT {*3 tests with 0 errors*}
880
fossil test-parse-all-blobs --wellformed
881
test crosslink-parse-all-wellformed {$CODE == 0}
882
crosslink_match crosslink-parse-all-wellformed-text $RESULT \
883
{*tests with 0 errors*}
884
885
# Crosslinking an artifact a second time changes nothing.
886
set crosslinkEvents [fossil_sql "SELECT count(*) FROM event"]
887
fossil test-crosslink $crosslinkM1
888
test crosslink-again {$CODE == 0}
889
fossil test-crosslink $crosslinkW1
890
test crosslink-again-wiki {$CODE == 0}
891
test_eq crosslink-again-events [fossil_sql "SELECT count(*) FROM event"] \
892
$crosslinkEvents
893
fossil test-crosslink -expectError
894
test crosslink-usage {$CODE != 0}
895
896
###############################################################################
897
# A rebuild reaches the same state from the artifacts alone.
898
899
set crosslinkState {SELECT (SELECT count(*) FROM event) || ' ' ||
900
(SELECT count(*) FROM attachment) || ' ' ||
901
(SELECT count(*) FROM forumpost) || ' ' ||
902
(SELECT count(*) FROM plink) || ' ' ||
903
(SELECT count(*) FROM mlink) || ' ' ||
904
(SELECT count(*) FROM ticket)}
905
set crosslinkBefore [fossil_sql $crosslinkState]
906
set crosslinkText [fossil_sql "SELECT group_concat(x, char(10)) FROM
907
(SELECT type || ' ' || comment AS x FROM event ORDER BY type, objid)"]
908
fossil rebuild
909
test crosslink-rebuild {$CODE == 0}
910
test_eq crosslink-rebuild-same-counts [fossil_sql $crosslinkState] \
911
$crosslinkBefore
912
test_eq crosslink-rebuild-same-events [fossil_sql "SELECT
913
group_concat(x, char(10)) FROM (SELECT type || ' ' || comment AS x
914
FROM event ORDER BY type, objid)"] $crosslinkText
915
fossil test-integrity
916
test crosslink-integrity {$CODE == 0}
917
918
###############################################################################
919
# The kind of an artifact that has no card naming its kind: a comment, a
920
# file or a parent card alone makes a check-in; none of them makes a
921
# control artifact, which has no entry in the timeline. Each row of the
922
# table has one of the three and no other.
923
924
foreach {crosslinkName crosslinkBody crosslinkKind} [list \
925
comment-only "C only\\sa\\scomment\nD 2026-03-01T10:00:00.000\nU alice\n" ci \
926
file-only "D 2026-03-01T10:01:00.000\nF a.txt $crosslinkFa\nU alice\n" ci \
927
parent-only "D 2026-03-01T10:02:00.000\nP $crosslinkC1\nU alice\n" ci \
928
none "D 2026-03-01T10:03:00.000\nT +sym-kind-test $crosslinkC1\nU alice\n" \
929
control \
930
] {
931
set crosslinkHash [crosslink_put $crosslinkBody]
932
test crosslink-mcdc-kind-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
933
test_eq crosslink-mcdc-kind-$crosslinkName-event [fossil_sql "SELECT
934
count(*) FROM event, blob WHERE objid=rid AND uuid='$crosslinkHash'
935
AND type='ci'"] [expr {$crosslinkKind eq "ci" ? 1 : 0}]
936
fossil test-parse-manifest [crosslink_file $crosslinkBody]
937
crosslink_match crosslink-mcdc-kind-$crosslinkName-parse $RESULT \
938
{*manifest_parse() worked*}
939
}
940
941
###############################################################################
942
# The links between a check-in and its parents when the parents arrive
943
# after it, in either order. A merge parent that arrives while the first
944
# parent is still missing adds no file links; they are added when the
945
# first parent arrives. A merge parent that arrives while the first
946
# parent is present adds them at once.
947
948
# The hash a check-in with the cards BODY will have, without storing it.
949
proc crosslink_hash {body} {
950
return [sha3_file [crosslink_file $body]]
951
}
952
953
# The number of file links that join the check-in CHILD to its parent
954
# PARENT.
955
proc crosslink_links {child parent} {
956
return [fossil_sql "SELECT count(*) FROM mlink WHERE
957
mid=(SELECT rid FROM blob WHERE uuid='$child')
958
AND pmid=(SELECT rid FROM blob WHERE uuid='$parent')"]
959
}
960
961
set crosslinkPA [crosslink_hash \
962
[join [list \
963
"C first\\sparent\nD 2026-03-02T10:00:00.000\n" \
964
"F a.txt $crosslinkFa\nU alice\n"] ""]]
965
set crosslinkPB [crosslink_hash \
966
[join [list \
967
"C second\\sparent\nD 2026-03-02T10:01:00.000\n" \
968
"F a.txt $crosslinkFb\nU alice\n"] ""]]
969
set crosslinkKid [crosslink_put "C merge\\skid
970
D 2026-03-02T11:00:00.000
971
F a.txt $crosslinkNone
972
P $crosslinkPA $crosslinkPB
973
U alice
974
"]
975
test crosslink-mcdc-merge-child {$CODE == 0 && $crosslinkKid ne ""}
976
test_eq crosslink-mcdc-merge-child-event [crosslink_event $crosslinkKid] \
977
{ci merge kid}
978
979
# The second parent first: no links yet.
980
set crosslinkGot [crosslink_put "C second\\sparent
981
D 2026-03-02T10:01:00.000
982
F a.txt $crosslinkFb
983
U alice
984
"]
985
test_eq crosslink-mcdc-merge-parent-first-hash $crosslinkGot $crosslinkPB
986
test_eq crosslink-mcdc-merge-parent-first-links \
987
[crosslink_links $crosslinkKid $crosslinkPB] 0
988
989
# Then the first parent: links to both.
990
set crosslinkGot [crosslink_put "C first\\sparent
991
D 2026-03-02T10:00:00.000
992
F a.txt $crosslinkFa
993
U alice
994
"]
995
test_eq crosslink-mcdc-merge-parent-second-hash $crosslinkGot $crosslinkPA
996
test_eq crosslink-mcdc-merge-parent-second-links \
997
[list [crosslink_links $crosslinkKid $crosslinkPA] \
998
[crosslink_links $crosslinkKid $crosslinkPB]] {1 1}
999
1000
# The first parent present, the second arriving later.
1001
set crosslinkQA [crosslink_hash \
1002
[join [list \
1003
"C other\\sfirst\nD 2026-03-02T12:00:00.000\n" \
1004
"F a.txt $crosslinkFa\nU alice\n"] ""]]
1005
set crosslinkQB [crosslink_hash \
1006
[join [list \
1007
"C other\\ssecond\nD 2026-03-02T12:01:00.000\n" \
1008
"F a.txt $crosslinkFb\nU alice\n"] ""]]
1009
crosslink_put "C other\\sfirst
1010
D 2026-03-02T12:00:00.000
1011
F a.txt $crosslinkFa
1012
U alice
1013
"
1014
set crosslinkKid2 [crosslink_put "C other\\skid
1015
D 2026-03-02T13:00:00.000
1016
F a.txt $crosslinkNone
1017
P $crosslinkQA $crosslinkQB
1018
U alice
1019
"]
1020
test_eq crosslink-mcdc-merge-second-missing-links \
1021
[list [crosslink_links $crosslinkKid2 $crosslinkQA] \
1022
[crosslink_links $crosslinkKid2 $crosslinkQB]] {1 0}
1023
crosslink_put "C other\\ssecond
1024
D 2026-03-02T12:01:00.000
1025
F a.txt $crosslinkFb
1026
U alice
1027
"
1028
test_eq crosslink-mcdc-merge-second-arrives-links \
1029
[list [crosslink_links $crosslinkKid2 $crosslinkQA] \
1030
[crosslink_links $crosslinkKid2 $crosslinkQB]] {1 1}
1031
1032
###############################################################################
1033
# An empty title on the first post of a forum thread is shown as deleted,
1034
# and an empty title or page text is null in the JSON form. Each row
1035
# differs from the one before in a single card.
1036
1037
foreach {crosslinkName crosslinkBody crosslinkWant crosslinkJson} [list \
1038
title \
1039
"D 2026-03-03T10:00:00.000\nH Some\\stitle\nU alice\n[crosslink_w {x}]" \
1040
{f Post: Some title} {*"H":"Some title"*"W":"x"*} \
1041
empty-title "D 2026-03-03T10:01:00.000\nH \nU alice\n[crosslink_w {x}]" \
1042
{f Post: (Deleted)} {*"H":null*"W":"x"*} \
1043
empty-text \
1044
"D 2026-03-03T10:02:00.000\nH Some\\stitle\nU alice\n[crosslink_w {}]" \
1045
{f Post: Some title} {*"H":"Some title"*"W":null*} \
1046
] {
1047
set crosslinkHash [crosslink_put $crosslinkBody]
1048
test crosslink-mcdc-forum-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1049
test_eq crosslink-mcdc-forum-$crosslinkName-event \
1050
[crosslink_event $crosslinkHash] $crosslinkWant
1051
fossil test-artifact-to-json $crosslinkHash
1052
crosslink_match crosslink-mcdc-forum-$crosslinkName-json $RESULT \
1053
$crosslinkJson
1054
}
1055
1056
# A wiki page with no text has a null W card in JSON.
1057
fossil test-artifact-to-json $crosslinkW3
1058
crosslink_match crosslink-mcdc-json-empty-wiki $RESULT \
1059
{*"type":"wiki"*"W":null*}
1060
1061
###############################################################################
1062
# A tag card whose value is empty reads like one with no value.
1063
1064
set crosslinkMin 10
1065
foreach {crosslinkName crosslinkCard crosslinkWant} [list \
1066
sym-empty "+sym-empty" {*Add tag "empty".} \
1067
other-empty "+other-empty" {*Add "other-empty".} \
1068
other-value "+other-value" {*Add "other-value" with value "v".} \
1069
] {
1070
set crosslinkValue [expr {$crosslinkName eq "other-value" ? "v" : ""}]
1071
set crosslinkHash [crosslink_put "D 2026-03-04T10:[incr crosslinkMin]:00.000
1072
T $crosslinkCard $crosslinkC1 $crosslinkValue
1073
U alice
1074
"]
1075
test crosslink-mcdc-tag-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1076
crosslink_match crosslink-mcdc-tag-$crosslinkName-event \
1077
[crosslink_event $crosslinkHash] "g Edit *:$crosslinkWant"
1078
}
1079
1080
###############################################################################
1081
# A check-in that picks a change from a check-in the repository has never
1082
# seen, and from one it has: only the second gets file links to it.
1083
1084
set crosslinkUnseen [string repeat 5a 20]
1085
foreach {crosslinkName crosslinkTarget} [list unseen $crosslinkUnseen \
1086
known $crosslinkM1] {
1087
set crosslinkHash [crosslink_put "C cherry-$crosslinkName
1088
D 2026-03-05T10:[incr crosslinkMin]:00.000
1089
F a.txt $crosslinkFa
1090
P $crosslinkC1
1091
Q +$crosslinkTarget
1092
U alice
1093
"]
1094
test crosslink-mcdc-cherry-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1095
test_eq crosslink-mcdc-cherry-$crosslinkName-event \
1096
[crosslink_event $crosslinkHash] "ci cherry-$crosslinkName"
1097
}
1098
test_eq crosslink-mcdc-cherry-unseen-not-stored [fossil_sql "SELECT count(*)
1099
FROM blob WHERE uuid='$crosslinkUnseen'"] 0
1100
1101
###############################################################################
1102
# The information page of a wiki page, asked for by the name of something
1103
# that is not a wiki page: a check-in, a ticket, a forum post, a file, and
1104
# a hash that names nothing.
1105
1106
proc crosslink_get {path} {
1107
return [fossil_http [file join [pwd] .rep.fossil] [request_get $path] \
1108
--ipaddr 127.0.0.1 --localauth]
1109
}
1110
1111
foreach {crosslinkName crosslinkHash crosslinkIs} [list \
1112
wiki $crosslinkW1 1 \
1113
checkin $crosslinkC1 0 \
1114
ticket $crosslinkT1 0 \
1115
forum $crosslinkF1 0 \
1116
file $crosslinkFa 0 \
1117
nothing $crosslinkNone2 0 \
1118
] {
1119
set crosslinkReply [crosslink_get /winfo?name=$crosslinkHash]
1120
test crosslink-mcdc-winfo-$crosslinkName \
1121
{[string match "HTTP/1.0 200*" $crosslinkReply]}
1122
test crosslink-mcdc-winfo-$crosslinkName-answer \
1123
{[string match "*No such object*" $crosslinkReply] == !$crosslinkIs}
1124
}
1125
1126
###############################################################################
1127
# A check-in on a delta manifest that removed a file, where the check-in
1128
# has the file again: the file is new in it. A file the delta manifest
1129
# does not mention is compared with the baseline's, so that l.txt, the
1130
# same as in the baseline, has no link, and the files the delta manifest
1131
# added or changed are removed.
1132
1133
set crosslinkBack [crosslink_put "C file-back-after-delta
1134
D 2026-03-06T10:00:00.000
1135
F a.txt $crosslinkFa
1136
F l.txt $crosslinkFa l
1137
P $crosslinkM2
1138
U alice
1139
"]
1140
test crosslink-mcdc-back-after-delta {$CODE == 0 && $crosslinkBack ne ""}
1141
test_eq crosslink-mcdc-back-after-delta-mlink [fossil_sql "SELECT
1142
group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1143
pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1144
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkBack')
1145
ORDER BY name)"] {a.txt:0:1 c.txt:1:0 d.txt:1:0}
1146
1147
###############################################################################
1148
# A delta manifest that removes a file its baseline does not have, and a
1149
# check-in on it: the check-in has no link for that name. The files of
1150
# the baseline that the check-in lacks are removed in it.
1151
1152
set crosslinkGhost [crosslink_put "B $crosslinkM1
1153
C delta-removes-unknown
1154
D 2026-03-07T10:00:00.000
1155
F zz-never.txt
1156
P $crosslinkM1
1157
U alice
1158
"]
1159
test crosslink-mcdc-delta-removes-unknown {$CODE == 0 && $crosslinkGhost ne ""}
1160
test_eq crosslink-mcdc-delta-removes-unknown-event \
1161
[crosslink_event $crosslinkGhost] {ci delta-removes-unknown}
1162
set crosslinkHash [crosslink_put "C child-of-delta-removes-unknown
1163
D 2026-03-07T10:01:00.000
1164
F a.txt $crosslinkFa x
1165
P $crosslinkGhost
1166
U alice
1167
"]
1168
test_eq crosslink-mcdc-delta-removes-unknown-child-mlink [fossil_sql "SELECT
1169
group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1170
pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1171
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
1172
ORDER BY name)"] {c.txt:1:0 l.txt:1:0}
1173
1174
###############################################################################
1175
# A delta manifest whose baseline is not in the repository is not a
1176
# check-in. A "parent" tag on it is recorded as its parent, and no file
1177
# links are made while the baseline is missing.
1178
1179
set crosslinkKid3 [crosslink_put "B [string repeat 6b 20]
1180
C delta-without-baseline
1181
D 2026-03-07T11:00:00.000
1182
F b.txt
1183
P $crosslinkC1
1184
U alice
1185
"]
1186
test crosslink-mcdc-reparent-no-baseline {$CODE == 0 && $crosslinkKid3 ne ""}
1187
test_eq crosslink-mcdc-reparent-no-baseline-no-event \
1188
[crosslink_event $crosslinkKid3] {}
1189
set crosslinkG [crosslink_put "D 2026-03-07T11:01:00.000
1190
T +parent $crosslinkKid3 $crosslinkM1
1191
U alice
1192
"]
1193
test crosslink-mcdc-reparent-no-baseline-tag {$CODE == 0 && $crosslinkG ne ""}
1194
test_eq crosslink-mcdc-reparent-no-baseline-plink [fossil_sql "SELECT count(*)
1195
FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkKid3')
1196
AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')"] 1
1197
test_eq crosslink-mcdc-reparent-no-baseline-no-links \
1198
[crosslink_links $crosslinkKid3 $crosslinkM1] 0
1199
1200
###############################################################################
1201
# A check-in whose parent is a wiki page, and a delta manifest whose
1202
# baseline is the same wiki page, stored by one command: the first is a
1203
# check-in, the second is not and is recorded as waiting for a baseline.
1204
1205
set crosslinkOnWiki [crosslink_file "C child-of-wiki-page
1206
D 2026-03-07T12:00:00.000
1207
F a.txt $crosslinkFa
1208
P $crosslinkW1
1209
U alice
1210
"]
1211
set crosslinkBasedOnWiki [crosslink_file "B $crosslinkW1
1212
C based-on-wiki-page
1213
D 2026-03-07T12:01:00.000
1214
F a.txt $crosslinkFa
1215
P $crosslinkC1
1216
U alice
1217
"]
1218
fossil test-content-put --crosslink $crosslinkOnWiki $crosslinkBasedOnWiki
1219
test crosslink-mcdc-wiki-baseline {$CODE == 0}
1220
test_eq crosslink-mcdc-wiki-baseline-events [fossil_sql "SELECT
1221
group_concat(comment, ' ') FROM event WHERE type='ci'
1222
AND comment IN ('child-of-wiki-page','based-on-wiki-page')"] \
1223
{child-of-wiki-page}
1224
fossil sha3sum $crosslinkBasedOnWiki
1225
test_eq crosslink-mcdc-wiki-baseline-waiting [fossil_sql "SELECT count(*)
1226
FROM orphan WHERE rid=(SELECT rid FROM blob
1227
WHERE uuid='[lindex $RESULT 0]')
1228
AND baseline=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
1229
1230
###############################################################################
1231
# Scripts that run when artifacts are stored by a command.
1232
#
1233
# A script for check-ins can ask for the JSON form of the parent of a
1234
# check-in that "branch new" makes. A common script that fails makes "ticket
1235
# add"
1236
# fail, after the ticket has been entered. A tag put on a wiki page by
1237
# "tag add" is recorded like a tag on a check-in.
1238
1239
proc crosslink_script {name script} {
1240
if {$script eq ""} {
1241
fossil sql "DELETE FROM config WHERE name='$name'"
1242
} else {
1243
fossil sql "REPLACE INTO config(name,value,mtime)
1244
VALUES('$name','$script',now())"
1245
}
1246
}
1247
1248
crosslink_script xfer-commit-script {query {SELECT artifact_to_json(pid) AS j
1249
FROM plink, blob WHERE cid=blob.rid AND blob.uuid=$uuid} {puts "PARENT $j"}}
1250
fossil branch new scripted $crosslinkM1
1251
test crosslink-mcdc-script-branch {$CODE == 0}
1252
crosslink_match crosslink-mcdc-script-branch-parent-json $RESULT \
1253
{*PARENT *&quot;type&quot;:&quot;checkin&quot;*&quot;C&quot;:&quot;crosslink-c2&quot;*}
1254
test_eq crosslink-mcdc-script-branch-made [fossil_sql "SELECT count(*)
1255
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
1256
AND tagname='sym-scripted'"] 1
1257
crosslink_script xfer-commit-script ""
1258
1259
set crosslinkTickets [fossil_sql "SELECT count(*) FROM ticket"]
1260
crosslink_script xfer-common-script {error common-script-says-no}
1261
fossil ticket add title Scripted status Open -expectError
1262
test crosslink-mcdc-script-ticket-fails {$CODE != 0}
1263
crosslink_match crosslink-mcdc-script-ticket-message $RESULT \
1264
{*common-script-says-no*}
1265
test_eq crosslink-mcdc-script-ticket-entered [fossil_sql "SELECT count(*)
1266
FROM ticket WHERE title='Scripted'"] 1
1267
crosslink_script xfer-common-script ""
1268
fossil ticket add title Unscripted status Open
1269
test crosslink-mcdc-no-script-ticket {$CODE == 0}
1270
test_eq crosslink-mcdc-no-script-ticket-count [fossil_sql "SELECT count(*)
1271
FROM ticket"] [expr {$crosslinkTickets + 2}]
1272
1273
fossil tag add on-a-wiki-page $crosslinkW1
1274
test crosslink-mcdc-tag-add-wiki {$CODE == 0}
1275
crosslink_match crosslink-mcdc-tag-add-wiki-event [fossil_sql "SELECT comment
1276
FROM event WHERE type='g' AND comment LIKE '%on-a-wiki-page%'"] \
1277
"Edit \\\[[string range $crosslinkW1 0 15]|*\\\]: Add *\"on-a-wiki-page\"."
1278
1279
###############################################################################
1280
# A repository made before cherrypicks were recorded has no table for
1281
# them. A check-in with a Q card is still a check-in there, and a
1282
# rebuild makes the table and records the cherrypick.
1283
1284
fossil sql "DROP TABLE cherrypick"
1285
set crosslinkHash [crosslink_put "C cherry-no-table
1286
D 2026-03-07T13:00:00.000
1287
F a.txt $crosslinkFa
1288
P $crosslinkC1
1289
Q +$crosslinkM1
1290
U alice
1291
"]
1292
test crosslink-mcdc-cherry-no-table {$CODE == 0 && $crosslinkHash ne ""}
1293
test_eq crosslink-mcdc-cherry-no-table-event [crosslink_event $crosslinkHash] \
1294
{ci cherry-no-table}
1295
test_eq crosslink-mcdc-cherry-no-table-still-none [fossil_sql "SELECT count(*)
1296
FROM sqlite_schema WHERE name='cherrypick'"] 0
1297
fossil rebuild
1298
test crosslink-mcdc-cherry-rebuild {$CODE == 0}
1299
test_eq crosslink-mcdc-cherry-rebuild-recorded [fossil_sql "SELECT count(*)
1300
FROM cherrypick WHERE childid=(SELECT rid FROM blob
1301
WHERE uuid='$crosslinkHash')"] 1
1302
1303
###############################################################################
1304
# The quick check for an artifact and the parser must agree.
1305
#
1306
# A signed artifact is an artifact. A check-in whose second card is a P
1307
# card that names no parent is an artifact. A signed artifact whose
1308
# signature does not end in a newline is not an artifact.
1309
1310
set crosslinkSigned "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n"
1311
append crosslinkSigned [read_file [crosslink_file \
1312
"D 2026-03-08T10:00:00.000\nL Signed\nU alice\n[crosslink_w {x}]"]]
1313
append crosslinkSigned "-----BEGIN PGP SIGNATURE-----\nabc\n"
1314
append crosslinkSigned "-----END PGP SIGNATURE-----"
1315
write_file wf-signed.txt "$crosslinkSigned\n"
1316
write_file wf-signed-no-newline.txt $crosslinkSigned
1317
set crosslinkEmptyP [crosslink_file \
1318
"D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"]
1319
1320
fossil test-parse-manifest wf-signed.txt
1321
crosslink_match crosslink-mcdc-agree-signed $RESULT \
1322
{*reports the input is ok*manifest_parse() worked}
1323
1324
fossil test-parse-manifest $crosslinkEmptyP
1325
crosslink_match crosslink-mcdc-agree-empty-p-parses $RESULT \
1326
{*manifest_parse() worked*}
1327
test crosslink-mcdc-agree-empty-p {![string match *disagree* $RESULT]}
1328
1329
fossil test-parse-manifest wf-signed-no-newline.txt
1330
crosslink_match crosslink-mcdc-agree-signed-no-newline-refused $RESULT \
1331
{*ERROR: not terminated*}
1332
test crosslink-mcdc-agree-signed-no-newline \
1333
{![string match *disagree* $RESULT]}
1334
1335
# The same for content held by a repository.
1336
fossil init wf.fossil
1337
fossil test-content-put -R wf.fossil wf-signed.txt $crosslinkEmptyP \
1338
wf-signed-no-newline.txt
1339
test crosslink-mcdc-agree-stored {$CODE == 0}
1340
fossil test-parse-all-blobs --wellformed -R wf.fossil
1341
test crosslink-mcdc-agree-stored-checked \
1342
{$CODE == 0 && [regexp {(\d+) tests with} $RESULT all n] && $n >= 3}
1343
crosslink_match crosslink-mcdc-agree-stored-no-errors $RESULT \
1344
{*tests with 0 errors*}
1345
1346
###############################################################################
1347
# More values of the "parent" tag. A value that ends in a space names the
1348
# parent before the space. A value long enough to be a hash that is not
1349
# one is ignored. A "parent" tag on a wiki page makes no links.
1350
1351
set crosslinkR1 [crosslink_put "C reparent-one
1352
D 2026-04-01T10:00:00.000
1353
U alice
1354
"]
1355
set crosslinkR2 [crosslink_put "C reparent-two
1356
D 2026-04-01T10:01:00.000
1357
P $crosslinkR1
1358
U alice
1359
"]
1360
set crosslinkR3 [crosslink_put "C reparent-three
1361
D 2026-04-01T10:02:00.000
1362
P $crosslinkR2
1363
U alice
1364
"]
1365
test crosslink-reparent-more-setup \
1366
{$crosslinkR1 ne "" && $crosslinkR2 ne "" && $crosslinkR3 ne ""}
1367
1368
# The primary parent of the check-in with the given hash.
1369
#
1370
proc crosslink_primary {hash} {
1371
return [fossil_sql "SELECT uuid FROM plink, blob WHERE pid=rid
1372
AND isprim AND cid=(SELECT rid FROM blob WHERE uuid='$hash')"]
1373
}
1374
1375
crosslink_put "D 2026-04-01T11:00:00.000
1376
T +parent $crosslinkR3 $crosslinkR1\\s
1377
U alice
1378
"
1379
test crosslink-reparent-trailing-space {$CODE == 0}
1380
test_eq crosslink-reparent-trailing-space-parent \
1381
[crosslink_primary $crosslinkR3] $crosslinkR1
1382
1383
crosslink_put "D 2026-04-01T11:01:00.000
1384
T +parent $crosslinkR2 [string repeat z 50]
1385
U alice
1386
"
1387
test crosslink-reparent-not-hex {$CODE == 0}
1388
test_eq crosslink-reparent-not-hex-ignored \
1389
[crosslink_primary $crosslinkR2] $crosslinkR1
1390
1391
set crosslinkHash [crosslink_put "D 2026-04-01T11:02:00.000
1392
L Reparented
1393
U alice
1394
[crosslink_w {text}]"]
1395
crosslink_put "D 2026-04-01T11:03:00.000
1396
T +parent $crosslinkHash $crosslinkR1
1397
U alice
1398
"
1399
test crosslink-reparent-wiki-page {$CODE == 0}
1400
test_eq crosslink-reparent-wiki-page-no-links [fossil_sql "SELECT count(*)
1401
FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')"] 0
1402
1403
###############################################################################
1404
# A check-in with two parents lists both in its JSON form.
1405
1406
set crosslinkHash [crosslink_put "C two-parents-json
1407
D 2026-04-01T12:00:00.000
1408
P $crosslinkR3 $crosslinkR1
1409
U alice
1410
"]
1411
test_eq crosslink-json-second-parent [fossil_sql "SELECT
1412
json_extract(artifact_to_json('$crosslinkHash'), '\$.P\[1\]')"] \
1413
$crosslinkR1
1414
1415
###############################################################################
1416
# A wiki page with two parents: both are linked, the first as the
1417
# primary one.
1418
1419
set crosslinkWa [crosslink_put "D 2026-04-02T10:00:00.000
1420
L Two\\sParents
1421
U alice
1422
[crosslink_w {one}]"]
1423
set crosslinkWb [crosslink_put "D 2026-04-02T10:01:00.000
1424
L Two\\sParents
1425
U alice
1426
[crosslink_w {other}]"]
1427
set crosslinkHash [crosslink_put "D 2026-04-02T10:02:00.000
1428
L Two\\sParents
1429
P $crosslinkWa $crosslinkWb
1430
U alice
1431
[crosslink_w {both}]"]
1432
test crosslink-wiki-two-parents {$CODE == 0 && $crosslinkHash ne ""}
1433
test_eq crosslink-wiki-two-parents-plink [fossil_sql "SELECT
1434
group_concat(uuid || ':' || isprim, ' ') FROM (SELECT uuid, isprim
1435
FROM plink, blob WHERE pid=rid AND cid=(SELECT rid FROM blob
1436
WHERE uuid='$crosslinkHash') ORDER BY isprim DESC)"] \
1437
"$crosslinkWa:1 $crosslinkWb:0"
1438
1439
###############################################################################
1440
# An artifact whose Z card does not match its text is stored, and is
1441
# nothing in the timeline.
1442
1443
write_file bad-z.txt "D 2026-04-02T11:00:00.000
1444
L Bad\\sSum
1445
U alice
1446
[crosslink_w {text}]Z [string repeat 0 32]\n"
1447
fossil test-content-put --crosslink bad-z.txt
1448
test crosslink-bad-z-stored \
1449
{$CODE == 0 && [regexp {inserted as record (\d+)} $RESULT all crosslinkRid]}
1450
test_eq crosslink-bad-z-no-event [fossil_sql "SELECT count(*) FROM event
1451
WHERE objid=$crosslinkRid"] 0
1452
test_eq crosslink-bad-z-no-page [fossil_sql "SELECT count(*) FROM tag
1453
WHERE tagname='wiki-Bad Sum'"] 0
1454
1455
###############################################################################
1456
# A version of a tech note that arrives after a later version of the same
1457
# note, and names the first version as its parent, does not replace the
1458
# later one in the timeline.
1459
1460
set crosslinkEid2 [string repeat e7 20]
1461
set crosslinkHash [crosslink_put "C note-first
1462
D 2026-04-03T10:00:00.000
1463
E 2026-04-03T09:00:00 $crosslinkEid2
1464
U alice
1465
[crosslink_w {first}]"]
1466
crosslink_put "C note-last
1467
D 2026-04-03T12:00:00.000
1468
E 2026-04-03T09:00:00 $crosslinkEid2
1469
P $crosslinkHash
1470
U alice
1471
[crosslink_w {last}]"
1472
crosslink_put "C note-middle
1473
D 2026-04-03T11:00:00.000
1474
E 2026-04-03T09:00:00 $crosslinkEid2
1475
P $crosslinkHash
1476
U alice
1477
[crosslink_w {middle}]"
1478
test crosslink-technote-middle-arrives-last {$CODE == 0}
1479
test_eq crosslink-technote-middle-arrives-last-event [fossil_sql "SELECT
1480
comment FROM event WHERE type='e' AND comment LIKE 'note-%'"] {note-last}
1481
1482
###############################################################################
1483
# Two delta manifests on one baseline, the second a child of the first.
1484
# The first changes a.txt, removes b.txt and adds x.txt. The second
1485
# names only b.txt, as removed: a.txt is the baseline's again and is
1486
# linked as changed; b.txt and x.txt get no link.
1487
1488
set crosslinkBase [crosslink_put "C two-deltas-base
1489
D 2026-04-04T10:00:00.000
1490
F a.txt $crosslinkFa
1491
F b.txt $crosslinkFb
1492
U alice
1493
"]
1494
set crosslinkDp [crosslink_put "B $crosslinkBase
1495
C two-deltas-parent
1496
D 2026-04-04T10:01:00.000
1497
F a.txt $crosslinkFb
1498
F b.txt
1499
F x.txt $crosslinkFa
1500
P $crosslinkBase
1501
U alice
1502
"]
1503
set crosslinkHash [crosslink_put "B $crosslinkBase
1504
C two-deltas-child
1505
D 2026-04-04T10:02:00.000
1506
F b.txt
1507
P $crosslinkDp
1508
U alice
1509
"]
1510
test crosslink-two-deltas {$CODE == 0 && $crosslinkHash ne ""}
1511
test_eq crosslink-two-deltas-event [crosslink_event $crosslinkHash] \
1512
{ci two-deltas-child}
1513
test_eq crosslink-two-deltas-mlink [fossil_sql "SELECT
1514
group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1515
pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1516
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
1517
ORDER BY name)"] {a.txt:1:1}
1518
1519
###############################################################################
1520
# Check-ins made within the same second, each the parent of the next, and
1521
# stored by one command: the timeline puts every parent before its child
1522
# for the first thirty, and leaves the rest at the time they carry.
1523
1524
set crosslinkFiles {}
1525
set crosslinkPrev ""
1526
for {set crosslinkI 0} {$crosslinkI < 33} {incr crosslinkI} {
1527
set crosslinkBody "C same-second-$crosslinkI\nD 2026-04-05T10:00:00.000\n"
1528
if {$crosslinkPrev ne ""} { append crosslinkBody "P $crosslinkPrev\n" }
1529
append crosslinkBody "U alice\n"
1530
set crosslinkFn [crosslink_file $crosslinkBody]
1531
fossil sha3sum $crosslinkFn
1532
set crosslinkPrev [lindex $RESULT 0]
1533
lappend crosslinkFiles $crosslinkFn
1534
}
1535
fossil test-content-put --crosslink {*}$crosslinkFiles
1536
test crosslink-same-second {$CODE == 0}
1537
test_eq crosslink-same-second-events [fossil_sql "SELECT count(*)
1538
FROM event WHERE comment LIKE 'same-second-%'"] 33
1539
test_eq crosslink-same-second-order [fossil_sql "SELECT count(*)
1540
FROM plink, event AS p, event AS c WHERE p.objid=pid AND c.objid=cid
1541
AND c.comment LIKE 'same-second-%' AND p.mtime<c.mtime"] 30
1542
test_eq crosslink-same-second-tip-time [fossil_sql "SELECT
1543
strftime('%Y-%m-%d %H:%M:%f', mtime) FROM event
1544
WHERE comment='same-second-32'"] {2026-04-05 10:00:00.000}
1545
1546
###############################################################################
1547
# A delta manifest whose baseline is missing, received by a pull: it is
1548
# stored and set aside until the baseline comes, and nothing is said.
1549
1550
fossil init xl-from.fossil
1551
fossil clone xl-from.fossil xl-pull.fossil
1552
test crosslink-pull-orphan-clone {$CODE == 0}
1553
set crosslinkFn [crosslink_file "B [string repeat 5c 20]
1554
C pulled-without-baseline
1555
D 2026-04-06T10:00:00.000
1556
F b.txt
1557
U alice
1558
"]
1559
fossil sha3sum $crosslinkFn
1560
set crosslinkHash [lindex $RESULT 0]
1561
fossil test-content-put -R xl-from.fossil --crosslink $crosslinkFn
1562
fossil pull xl-from.fossil -R xl-pull.fossil
1563
test crosslink-pull-orphan {$CODE == 0}
1564
fossil sql -R xl-pull.fossil "SELECT count(*) FROM orphan, blob
1565
WHERE orphan.rid=blob.rid AND uuid='$crosslinkHash'"
1566
test_eq crosslink-pull-orphan-set-aside [string trim $RESULT] 1
1567
fossil sql -R xl-pull.fossil "SELECT count(*) FROM event, blob
1568
WHERE objid=rid AND uuid='$crosslinkHash'"
1569
test_eq crosslink-pull-orphan-no-event [string trim $RESULT] 0
1570
1571
###############################################################################
1572
# Artifacts that name a shunned artifact. No placeholder is made for it.
1573
# A cluster that lists it still clears its other members. A tag on it is
1574
# in the timeline and tags nothing. A check-in with it as second parent
1575
# gets file links to its first parent only.
1576
1577
set crosslinkShun [string repeat 5e 20]
1578
fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$crosslinkShun',0)"
1579
set crosslinkHash [crosslink_put "C shun-clustered
1580
D 2026-04-07T10:00:00.000
1581
U alice
1582
"]
1583
test_eq crosslink-shun-unclustered-before [fossil_sql "SELECT count(*)
1584
FROM unclustered, blob WHERE unclustered.rid=blob.rid
1585
AND uuid='$crosslinkHash'"] 1
1586
crosslink_put [join [lsort [list "M $crosslinkShun" "M $crosslinkHash"]] \n]\n
1587
test crosslink-shun-cluster {$CODE == 0}
1588
test_eq crosslink-shun-cluster-clears-other [fossil_sql "SELECT count(*)
1589
FROM unclustered, blob WHERE unclustered.rid=blob.rid
1590
AND uuid='$crosslinkHash'"] 0
1591
1592
set crosslinkG [crosslink_put "D 2026-04-07T10:01:00.000
1593
T +sym-on-shunned $crosslinkShun
1594
U alice
1595
"]
1596
test crosslink-shun-tag {$CODE == 0 && $crosslinkG ne ""}
1597
crosslink_match crosslink-shun-tag-event [crosslink_event $crosslinkG] \
1598
{g Edit \[5e5e5e5e5e5e5e5e|5e5e5e5e5e\]: Add tag "on-shunned".}
1599
test_eq crosslink-shun-tag-tags-nothing [fossil_sql "SELECT count(*)
1600
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
1601
AND tagname='sym-on-shunned'"] 0
1602
1603
set crosslinkKid [crosslink_put "C shun-merge-kid
1604
D 2026-04-07T11:00:00.000
1605
F a.txt $crosslinkFb
1606
P $crosslinkR1 $crosslinkShun
1607
U alice
1608
"]
1609
test crosslink-shun-merge-parent {$CODE == 0 && $crosslinkKid ne ""}
1610
test_eq crosslink-shun-merge-parent-links \
1611
[crosslink_links $crosslinkKid $crosslinkR1] 1
1612
test_eq crosslink-shun-no-placeholder [fossil_sql "SELECT count(*)
1613
FROM blob WHERE uuid='$crosslinkShun'"] 0
1614
fossil sql "DELETE FROM shun WHERE uuid='$crosslinkShun'"
1615
1616
###############################################################################
1617
# A common script that fails makes "branch new" fail.
1618
1619
crosslink_script xfer-common-script {error common-script-refuses}
1620
fossil branch new refused $crosslinkR1 -expectError
1621
test crosslink-script-branch-fails {$CODE != 0}
1622
crosslink_match crosslink-script-branch-message $RESULT \
1623
{*common-script-refuses*}
1624
crosslink_script xfer-common-script ""
1625
1626
###############################################################################
1627
# A repository whose record of an attachment has an empty source in place
1628
# of none: a tech note or ticket stored for the same target words the
1629
# attachment as deleted.
1630
1631
set crosslinkEid3 [string repeat e9 20]
1632
set crosslinkTkt3 [string repeat c9 20]
1633
set crosslinkAe [crosslink_put "A note.txt $crosslinkEid3 $crosslinkSrc
1634
D 2026-04-08T10:00:00.000
1635
U alice
1636
"]
1637
set crosslinkAt [crosslink_put "A tkt.txt $crosslinkTkt3 $crosslinkSrc
1638
D 2026-04-08T10:01:00.000
1639
U alice
1640
"]
1641
test crosslink-attach-empty-source-setup \
1642
{$crosslinkAe ne "" && $crosslinkAt ne ""}
1643
fossil sql "UPDATE attachment SET src=''
1644
WHERE target IN ('$crosslinkEid3','$crosslinkTkt3')"
1645
crosslink_put "C attached-note
1646
D 2026-04-08T11:00:00.000
1647
E 2026-04-08T09:00:00 $crosslinkEid3
1648
U alice
1649
[crosslink_w {note}]"
1650
test crosslink-attach-empty-source-technote {$CODE == 0}
1651
crosslink_match crosslink-attach-empty-source-technote-event \
1652
[crosslink_event $crosslinkAe] \
1653
{e Delete attachment "note.txt" from tech note \[/technote/*\]}
1654
crosslink_put "D 2026-04-08T11:01:00.000
1655
J title Attached
1656
K $crosslinkTkt3
1657
U alice
1658
"
1659
test crosslink-attach-empty-source-ticket {$CODE == 0}
1660
crosslink_match crosslink-attach-empty-source-ticket-event \
1661
[crosslink_event $crosslinkAt] \
1662
{t Delete attachment "tkt.txt" from ticket \[*\]}
1663
1664
###############################################################################
1665
1666
test_cleanup
1667

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button