Skip to content

Commit f55642f

Browse files
authored
Merge pull request #164 from unisoncomputing/cp/reject-ambiguous-element-orderings
Reject ambiguous element orderings
2 parents 2a97fc5 + 34c4abb commit f55642f

File tree

56 files changed

+1034
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1034
-321
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ jobs:
330330
331331
# Install ucm
332332
mkdir ucm
333-
curl -L https://github.com/unisonweb/unison/releases/download/release%2F0.5.47/ucm-linux-x64.tar.gz | tar -xz -C ucm
333+
curl -L https://github.com/unisonweb/unison/releases/download/release%2F1.0.0/ucm-linux-x64.tar.gz | tar -xz -C ucm
334334
export PATH=$PWD/ucm:$PATH
335335
336336
# Start share and it's dependencies in the background

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ SHARE_PROJECT_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
44
export SHARE_PROJECT_ROOT
55
UNAME := $(shell uname)
66
STACK_FLAGS := "--fast"
7-
dist_dir := $(shell stack path | awk '/^dist-dir/{print $$2}')
87
exe_name := share-api
9-
exe := $(dist_dir)/build/$(exe_name)/$(exe_name)
8+
exe := $(shell stack exec -- which $(exe_name))
109
target_dir := docker/tmp
1110
installed_share := $(target_dir)/$(exe_name)
1211
unison := $(shell command -v unison)
@@ -27,10 +26,9 @@ endif
2726
$(target_dir):
2827
mkdir $@
2928

30-
$(exe): $(shell find . unison -type f -name '*.hs') $(shell find . unison -type f -name '*.yaml')
31-
@echo $(exe)
32-
@echo $@
33-
stack build $(STACK_FLAGS)
29+
$(exe): $(shell fd '' . unison --type file -e hs 2>/dev/null || find . unison -type f -name '*.hs') $(shell fd '' . unison --type file -e yaml 2>/dev/null || find . unison -type f -name '*.yaml')
30+
@echo Building $(exe_name)
31+
stack build $(STACK_FLAGS) $(exe_name)
3432

3533
$(installed_share): $(exe) $(target_dir)
3634
cp $(exe) $(installed_share)

share-api/src/Share/Web/UCM/Sync/Impl.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Share.Web.Errors
5252
import Share.Web.UCM.Sync.HashJWT qualified as HashJWT
5353
import Share.Web.UCM.Sync.Types (EntityBunch (..), RepoInfoKind (..), entityKind)
5454
import U.Codebase.Causal qualified as Causal
55+
import U.Codebase.Sqlite.HashHandle qualified as HH
5556
import U.Codebase.Sqlite.Orphans ()
5657
import Unison.Codebase.Path qualified as Path
5758
import Unison.Hash32 (Hash32)
@@ -259,11 +260,11 @@ insertEntitiesToCodebase codebase entities = do
259260
mayErrs <- PG.transactionUnsafeIO $ batchValidateEntities maxParallelismPerUploadRequest isComponentHashMismatchAllowedIO isCausalHashMismatchAllowedIO unsavedEntities
260261
case mayErrs of
261262
Nothing -> pure ()
262-
Just (err :| _errs) -> throwError err
263-
-- case err of
264-
-- Right e -> throwError e
265-
-- Left () ->
266-
-- throwError $ Sync.InvalidByteEncoding (Hash32.fromHash hash) Sync.TermComponentType "Incomplete element ordering in term components"
263+
Just (err :| _errs) ->
264+
case err of
265+
Right e -> throwError e
266+
Left (HH.IncompleteElementOrderingError (ComponentHash hash)) ->
267+
throwError $ Sync.InvalidByteEncoding (Hash32.fromHash hash) Sync.TermComponentType "Incomplete element ordering in term components"
267268
SyncQ.saveTempEntities codebase unsavedEntities
268269
let hashesNowInTemp = Set.fromList (fst <$> Foldable.toList unsavedEntities) <> (Set.fromList . Foldable.toList $ hashesAlreadyInTemp)
269270
pure hashesNowInTemp
@@ -397,7 +398,7 @@ batchValidateEntities ::
397398
(ComponentHash -> ComponentHash -> IO Bool) ->
398399
(CausalHash -> CausalHash -> IO Bool) ->
399400
f (Hash32, Sync.Entity Text Hash32 Hash32) ->
400-
IO (Maybe (NonEmpty Sync.EntityValidationError))
401+
IO (Maybe (NonEmpty (Either HH.HashingFailure Sync.EntityValidationError)))
401402
batchValidateEntities maxParallelism checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed entities = do
402403
errs <- UnliftIO.pooledForConcurrentlyN maxParallelism entities \(hash, entity) ->
403404
validateEntity checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed hash entity
@@ -409,16 +410,16 @@ validateEntity ::
409410
(CausalHash -> CausalHash -> m Bool) ->
410411
Hash32 ->
411412
Share.Entity Text Hash32 Hash32 ->
412-
m (Maybe Sync.EntityValidationError)
413+
m (Maybe (Either HH.HashingFailure Sync.EntityValidationError))
413414
validateEntity checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed hash entity = do
414415
case (Sync.validateEntity hash entity) of
415-
Just (err@(Sync.EntityHashMismatch Sync.TermComponentType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash}))) ->
416+
Just (Right (err@(Sync.EntityHashMismatch Sync.TermComponentType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash})))) ->
416417
checkIfComponentHashMismatchIsAllowed (ComponentHash . Hash32.toHash $ expectedHash) (ComponentHash . Hash32.toHash $ actualHash) >>= \case
417-
False -> pure (Just err)
418+
False -> pure (Just $ Right err)
418419
True -> pure Nothing
419-
Just (err@(Sync.EntityHashMismatch Sync.CausalType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash}))) ->
420+
Just (Right (err@(Sync.EntityHashMismatch Sync.CausalType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash})))) ->
420421
checkIfCausalHashMismatchIsAllowed (CausalHash . Hash32.toHash $ expectedHash) (CausalHash . Hash32.toHash $ actualHash) >>= \case
421-
False -> pure (Just err)
422+
False -> pure (Just $ Right err)
422423
True -> pure Nothing
423424
Just err ->
424425
-- This shouldn't happen unless the ucm client is buggy or malicious

share-task-runner/src/Share/Tasks/AmbiguousComponentCheck.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Share.Postgres.Cursors qualified as PG
88
import Share.Prelude
99
import Share.Utils.Logging (Loggable (..))
1010
import Share.Utils.Logging qualified as Logging
11+
import U.Codebase.Sqlite.HashHandle qualified as HH
1112
import U.Codebase.Sqlite.TempEntity
1213
import Unison.Hash32
1314
import Unison.Sync.EntityValidation qualified as EV
@@ -17,7 +18,7 @@ import Unison.Util.Servant.CBOR qualified as CBOR
1718

1819
data AmbiguousComponentCheckError
1920
= TaskAmbiguousComponentCheckError Hash32
20-
| TaskEntityValidationError Hash32 (Sync.EntityValidationError)
21+
| TaskEntityValidationError Hash32 (Either HH.HashingFailure Sync.EntityValidationError)
2122
| TaskEntityDecodingError Hash32 CBOR.DeserialiseFailure
2223
deriving (Show, Eq)
2324

transcripts/run-transcripts.zsh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ done;
1212

1313
source "$(realpath "$(dirname "$0")")/transcript_helpers.sh"
1414

15-
# Base directory containing all transcripts
15+
echo "UCM Version: $(transcript_ucm --version)"
16+
17+
# Base directory containing share-api transcripts
1618
transcripts_location="transcripts/share-apis"
1719

1820
# Find all directories within transcripts_location

transcripts/share-apis/branch-browse/branch-find.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
{
137137
"annotation": {
138138
"contents": "#r7hq9rqc3hebqailf77f656vbgice0716c6f0j7bj06muhj5ac1pq103gdh5974f14fcbmvp44fai5in1ajp5j3ejckfp6bffd3fpoo",
139+
"fqn": "Remote",
139140
"tag": "TypeReference"
140141
},
141142
"segment": "Remote"

transcripts/share-apis/code-browse/codebase-definition-by-hash-constructor.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
{
4545
"annotation": {
4646
"contents": "#6kbe32g06nqg93cqub6ohqc4ql4o49ntgnunifds0t75qre6lacnbsr3evn8bkivj68ecbvmhkbak4dbg4fqertcpgb396rmo34tnh0#d0",
47+
"fqn": "names.Thing.This",
4748
"tag": "TermReference"
4849
},
4950
"segment": "This"
@@ -57,6 +58,7 @@
5758
{
5859
"annotation": {
5960
"contents": "#6kbe32g06nqg93cqub6ohqc4ql4o49ntgnunifds0t75qre6lacnbsr3evn8bkivj68ecbvmhkbak4dbg4fqertcpgb396rmo34tnh0#d1",
61+
"fqn": "names.Thing.That",
6062
"tag": "TermReference"
6163
},
6264
"segment": "That"

transcripts/share-apis/code-browse/codebase-definition-by-hash-term.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{
1010
"annotation": {
1111
"contents": "##Nat",
12+
"fqn": "builtin.Nat",
1213
"tag": "TypeReference"
1314
},
1415
"segment": "Nat"
@@ -36,6 +37,7 @@
3637
{
3738
"annotation": {
3839
"contents": "##Nat",
40+
"fqn": "builtin.Nat",
3941
"tag": "TypeReference"
4042
},
4143
"segment": "Nat"

transcripts/share-apis/code-browse/codebase-definition-by-name-encoded.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
{
5050
"annotation": {
5151
"contents": "##Nat",
52+
"fqn": "builtin.Nat",
5253
"tag": "TypeReference"
5354
},
5455
"segment": "Nat"
@@ -128,6 +129,7 @@
128129
{
129130
"annotation": {
130131
"contents": "##Nat",
132+
"fqn": "builtin.Nat",
131133
"tag": "TypeReference"
132134
},
133135
"segment": "Nat"

transcripts/share-apis/code-browse/codebase-definition-by-name-should-minimally-suffix-again.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{
1010
"annotation": {
1111
"contents": "##Nat",
12+
"fqn": "builtin.Nat",
1213
"tag": "TypeReference"
1314
},
1415
"segment": "Nat"
@@ -36,6 +37,7 @@
3637
{
3738
"annotation": {
3839
"contents": "##Nat",
40+
"fqn": "builtin.Nat",
3941
"tag": "TypeReference"
4042
},
4143
"segment": "Nat"

0 commit comments

Comments
 (0)