Repository navigation
fix(creation): report a never-supplied version as version_required, not revision_conflict #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fcy222fcy
wants to merge
2
commits into
ThinkFlowLab:main
Choose a base branch
from
fcy222fcy:fix/version-required-preconditions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| """A version the caller never supplied reports version_required, not conflict.""" | ||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
|
|
||
| from opendirector.application.creation_canvas import asset_ref | ||
| from opendirector.infrastructure.creation_projects import CreationProjects | ||
| from opendirector.infrastructure.local_projects import LocalProjects | ||
| from test_creation_canvas_service import media, project, send, text_material, ver | ||
| from test_creation_timeline_render import prepared | ||
|
|
||
|
|
||
| pytestmark = pytest.mark.cpu | ||
|
|
||
|
|
||
| def issue_of(receipt): | ||
| assert receipt.status == 'rejected', receipt | ||
| return receipt.issues[0] | ||
|
|
||
|
|
||
| def test_reference_add_locking_an_empty_node_reports_the_node_version(project): | ||
| store, pid, session = project | ||
| source, _ = text_material(project) | ||
| target, spec = media(project) | ||
| ref = dict(id=uuid4(), projectId=pid, binding='follow_current', source=dict(id=source.id), targetSpecId=spec.id) | ||
| issue = issue_of(send(store, pid, 'reference.add', session=session, | ||
| versions=[ver('generation_spec', spec)], reference=ref)) | ||
| assert issue.code == 'version_required', ( | ||
| f'a never-supplied canvas_item version is reported as {issue.code!r}: {issue.message}') | ||
| assert f'"objectType":"canvas_item","id":"{target.id}"' in issue.message, issue.message | ||
| assert f'--expected-version canvas_item:{target.id}:{target.revision}' in issue.message, issue.message | ||
|
|
||
|
|
||
| def test_materialize_replacing_a_configured_draft_reports_the_spec_version(project): | ||
| store, pid, session = project | ||
| spec_id, item_id = uuid4(), uuid4() | ||
| assert send(store, pid, 'creation.batch', session=session, operations=[ | ||
| dict(type='generationSpec.create', payload=dict(spec=dict(id=spec_id, projectId=pid, kind='text', | ||
| purpose='draft', prompt='hand-tuned opening'))), | ||
| dict(type='canvas.show', payload=dict(item=dict(id=item_id, projectId=pid, kind='text', | ||
| binding=dict(role='empty', draftSpec=dict(id=spec_id)))))]).status == 'applied' | ||
| assert send(store, pid, 'asset.writeText', session=session, name='slot.md', text='v1').status == 'applied' | ||
| snapshot = store.snapshot(pid) | ||
| item = next(i for i in snapshot.canvasItems if i.id == item_id) | ||
| spec = next(s for s in snapshot.generationSpecs if s.id == spec_id) | ||
| asset = snapshot.assets[-1] | ||
| issue = issue_of(send(store, pid, 'canvas.materialize', session=session, | ||
| versions=[ver('canvas_item', item)], itemId=item_id, asset=asset_ref(asset), discardGenerationDraft=True)) | ||
| assert issue.code == 'version_required', ( | ||
| f'a never-supplied generation_spec version is reported as {issue.code!r}: {issue.message}') | ||
| assert f'"objectType":"generation_spec","id":"{spec_id}"' in issue.message, issue.message | ||
| assert f'--expected-version generation_spec:{spec_id}:{spec.revision}' in issue.message, issue.message | ||
| assert send(store, pid, 'canvas.materialize', session=session, | ||
| versions=[ver('canvas_item', item), ver('generation_spec', spec)], | ||
| itemId=item_id, asset=asset_ref(asset), discardGenerationDraft=True).status == 'applied' | ||
|
|
||
|
|
||
| @pytest.mark.anyio | ||
| async def test_batch_edit_requiring_an_existing_document_reports_its_version(project): | ||
| from test_creation_image_edits import edit_command, generated | ||
| store, pid, session = project | ||
| runner, _ = await generated(project) | ||
| try: | ||
| assert store.execute(edit_command(project), session=session).status == 'applied' | ||
| command = edit_command(project) | ||
| stripped = [value for value in command.expectedVersions if value.objectType != 'editor_document'] | ||
| issue = issue_of(store.execute(command.model_copy(update={'expectedVersions': stripped}), session=session)) | ||
| assert issue.code == 'version_required', ( | ||
| f'a never-supplied editor_document version is reported as {issue.code!r}: {issue.message}') | ||
| assert '"objectType":"editor_document"' in issue.message, issue.message | ||
| finally: | ||
| await runner.close() | ||
|
|
||
|
|
||
| def test_repeat_render_without_the_output_revision_reports_it(project): | ||
| from opendirector.application.creation_tool_assets import CreationToolAssets | ||
| from opendirector.domain.creation.assets import AssetProvenance | ||
| from opendirector.domain.creation.commands import parse_command | ||
| from test_creation_timeline_render import clip | ||
| store, pid, session = project | ||
| _, _, versions, payload = prepared(project) | ||
| assert send(store, pid, 'timeline.publishRender', session=session, versions=versions, **payload).status == 'applied' | ||
| before = store.snapshot(pid) | ||
| target = next(i for i in before.canvasItems if i.id == payload['outputId']) | ||
| record = CreationToolAssets(store).import_file(pid, uuid4(), 'second-render.mp4', clip(color='red'), session, | ||
| provenance=AssetProvenance(source='upload')) | ||
| second = CreationToolAssets(store).assets.get(pid, record['id']) | ||
| source, editor = before.canvasItems[0], before.editorDocuments[0] | ||
| command = parse_command(dict(commandId=uuid4(), projectId=pid, type='timeline.publishRender', | ||
| expectedVersions=[ver('canvas_item', source), ver('editor_document', editor), ver('asset', second)], | ||
| payload={**payload, 'asset': asset_ref(second)})) | ||
| issue = issue_of(store.execute(command, session=session)) | ||
| assert issue.code == 'version_required', ( | ||
| f'a never-supplied output revision is reported as {issue.code!r}: {issue.message}') | ||
| assert f'"objectType":"canvas_item","id":"{target.id}"' in issue.message, issue.message | ||
| assert f'--expected-version canvas_item:{target.id}:{target.revision}' in issue.message, issue.message | ||
| assert 'payload.expectedOutputRevision' in issue.message, issue.message | ||
| hinted = parse_command(dict(commandId=uuid4(), projectId=pid, type='timeline.publishRender', | ||
| expectedVersions=[ver('canvas_item', source), ver('editor_document', editor), ver('asset', second), | ||
| ver('canvas_item', target)], | ||
| payload={**payload, 'asset': asset_ref(second), 'expectedOutputRevision': target.revision})) | ||
| assert store.execute(hinted, session=session).status == 'applied', 'retry per the message must publish' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这条提示只让调用方补
--expected-version canvas_item:…,但这里判断的是payload.expectedOutputRevision。照提示重试还是会报缺版本;而只填 payload,命令层也会要求expectedVersions。建议把两个字段都写进提示,并测一次照提示补齐后能成功发布。