typelevel / typelevel/weaver-test
Add explicit unique ResourceTag-like keys
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 85
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
This issue was copied over from: https://github.com/disneystreaming/weaver-test/issues/266
It was opened by: nigredo-tori
This is inspired by the vault library.
At the moment global resources are indexed by ResourceTags and labels. This has its issues:
- The default
ResourceTagimplementation derives its identity fromClassTag. This leads to a possibility of collisions, as stated in the documentation. The suggested workarounds are monomorphic wrappers or customResourceTaginstances. - Labels mitigate the collision problem somewhat (or, rather, leave it up to discipline). But the labels are not tied to resource types, so it's easy to mix up which labels correspond to which resource.
Instead, we can create objects that are guaranteed to be unique, and which are associated with a specific type. Consider something like this:
// default `equals` - different objects are never equal.
final private class UniqueResourceTag[A](
val description: String
) extends ResourceTag[A] {
def cast(obj: Any): Option[A] = Some(obj.asInstanceOf[A])
}
def unsafeCreateUniqueTag[A](description: String): ResourceTag[A] =
new UniqueResourceTag[A](description)
This can be used as follows:
// A "constant" somewhere in a common object
val fooTag = unsafeCreateUniqueTag[Foo]("")
// Inside a suite
global.getR()(fooTag)
The current API is obviously not perfect for this, but the general idea should be clear enough. Note that there's no way for fooTag to collide with anything else (assuming no broken equals implentations), and there's no way to mistake the type of the resource it points to.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the current ResourceTag and global resource APIs, then compare their identity and type-association behavior with the vault-inspired proposal. Done means the API supports explicitly created unique tags associated with a resource type, without collisions or confusion between resource labels and types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100