accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
280 stars 119 forks source link

CLI: `cicero get` command pulls in obsolete external models. #793

Open martinhalford opened 1 year ago

martinhalford commented 1 year ago

Bug Report 🐛

Context

As part of the process of updating the unit tests for the Cicero repo, I am updating the many model.cto files to include the new Concerto syntax (e.g. adding versions to the namespaces, adding @template to assets and updating import statements).

Once these model.cto files have been updated, I am deleting all external model *.cto files from model folder in order to allow Cicero to correctly import the correct external reference files.

This leaves a clean \model folder containing a single model.cto file.

I then run cicero get which, I assumed, would pull the latest reference .cto files from the Model Repository.

Example

For example, starting with the following model file from [here](https://github.com/accordproject/cicero/blob/main/packages/cicero-cli/test/data/helloemit/model/model.cto) I modified it to be as so:

namespace org.accordproject.helloemit@1.0.0

import org.accordproject.contract@0.2.0.{Clause, Contract} from https://models.accordproject.org/accordproject/contract@0.2.0.cto
import org.accordproject.runtime@0.2.0.{Request, Response, State, Obligation} from https://models.accordproject.org/accordproject/runtime@0.2.0.cto

/**
 * The template model
 */
@template
asset TemplateModel extends Clause {
  /**
   * The name for the clause
   */
  o String name
}

transaction MyRequest extends Request {
  o String input
}

transaction MyResponse extends Response {
  o String output
}

event Greeting {
  o String message
}

The cicero get command throws an error and drags in the obsolete @models.accordproject.org.accordproject.contract.cto file.

See command history:

$ cd /Users/martin/Dev/accord/cicero/packages/cicero-cli/test/data/helloemit/     
$ ls -l ./model
total 8
-rw-r--r--@ 1 martin  staff  622  8 Aug 14:49 model.cto
$ cicero get
 INFO: Using current directory as template folder
 ERROR: Failed to find an asset that extends org.accordproject.contract.Clause. The model for the template must contain a single asset that extends org.accordproject.contract.Clause.
$ ls -l ./model                                                              
total 32
-rw-r--r--@ 1 martin  staff   975  8 Aug 15:06 @models.accordproject.org.accordproject.contract.cto
-rw-r--r--@ 1 martin  staff   979  8 Aug 15:06 @models.accordproject.org.accordproject.contract@0.2.0.cto
-rw-r--r--@ 1 martin  staff  1511  8 Aug 15:06 @models.accordproject.org.accordproject.runtime@0.2.0.cto
-rw-r--r--@ 1 martin  staff   622  8 Aug 14:49 model.cto

Expected Behaviour

Context (Environment)

% cicero --version
0.24.1-20230722135139
DianaLease commented 1 year ago

Is cicero get just a wrapper of concerto get or does it behave differently? Wondering if you tried the latter and had the same issue?

martinhalford commented 1 year ago

Hi @DianaLease - Interesting. I tried concerto get and it worked fine.

This is the model.cto:

namespace org.accordproject.helloemit@1.0.0

import org.accordproject.contract@0.2.0.{Clause, Contract} from https://models.accordproject.org/accordproject/contract@0.2.0.cto
import org.accordproject.runtime@0.2.0.{Request, Response, State, Obligation} from https://models.accordproject.org/accordproject/runtime@0.2.0.cto

/**
 * The template model
 */
@template
asset TemplateModel extends Clause {
  /**
   * The name for the clause
   */
  o String name
}

transaction MyRequest extends Request {
  o String input
}

transaction MyResponse extends Response {
  o String output
}

event Greeting {
  o String message
}

I then ran the following command:

$ concerto get --model ./model.cto --output ./output

The output was as execped - just the @0.2.0 files:

$ cd output 
$ ls -l
total 24
-rw-r--r--@ 1 martin  staff   979 10 Aug 10:14 @models.accordproject.org.accordproject.contract@0.2.0.cto
-rw-r--r--@ 1 martin  staff  1511 10 Aug 10:14 @models.accordproject.org.accordproject.runtime@0.2.0.cto
-rw-r--r--@ 1 martin  staff   622 10 Aug 10:14 model.cto

I then ran the cicero command as follows:

$ cicero get

This is the output which also included the erroneous contract.cto file:

$ cd model 
model % ls -l
total 32
-rw-r--r--@ 1 martin  staff   975 10 Aug 10:16 @models.accordproject.org.accordproject.contract.cto
-rw-r--r--@ 1 martin  staff   979 10 Aug 10:16 @models.accordproject.org.accordproject.contract@0.2.0.cto
-rw-r--r--@ 1 martin  staff  1511 10 Aug 10:16 @models.accordproject.org.accordproject.runtime@0.2.0.cto
-rw-r--r--@ 1 martin  staff   622 10 Aug 10:14 model.cto

The file contract.cto looked like this:

 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

concerto version ">= 1.0.0"

namespace org.accordproject.contract

/**
 * Contract Data
 * -- Describes the structure of contracts and clauses
 */

/* A contract is a asset -- This contains the contract data */
abstract asset Contract identified by contractId {
  o String contractId
}

/* A clause is an asset -- This contains the clause data */
abstract asset Clause identified by clauseId {
  o String clauseId
}

Versions

Concerto: 3.12.0 Cicero: 0.24.1-20230722135139