-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add ooni test descriptors. #275
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
base: main
Are you sure you want to change the base?
Conversation
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.
I feel we should remove Defaults descriptors all together. If we don't have them anymore, we don't need the extra complexity. That means:
- No need to keep both
Descriptor
andInstalledTestDescriptorModel
classes Descriptor.Source
is not neededDefaultTestDescriptor
is not neededGetDefaultTestDescriptors
is not needed- Only
isDefault()
method is needed, theisInstalledNonDefaultDescriptor()
should just be!isDefault()
.
That should simplify a lot of the existing code.
|
||
val isDefaultTestDescriptor get() = id.value in 10470..10474 // TODO(aanorbel): switch to OONI reserved namespace | ||
|
||
val key get() = if (isDefaultTestDescriptor) { |
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.
This is more like a settings key now no? Just to make it clear why we still need this. Because for all other purposes now we can use the ID.
Maybe we can keep both Descriptor and InstalledTestDescriptorModel. It may be useful for the |
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.
I found a bug. When you just have the OONI descriptors, and no custom descriptor installed, the pull-to-refresh on the Dashboard screen doesn't seem to work. The refresh icon just says at the top without animation.
} | ||
} | ||
companion object { | ||
fun fromDescriptor(descriptor: Descriptor) = descriptor.source.id |
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.
This companion object isn't needed, it should return an object of the type Test
, or it should be called something like sourceFromDescriptor
. It's weird that a static factory method only returns a specific field inside its class.
@Serializable | ||
data class Test( | ||
val source: Source, | ||
val source: InstalledTestDescriptorModel.Id? = null, |
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.
Maybe call this sourceId or descriptorId to avoid confusion?
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.
And this should never be null right?
RunSpecification.Full( | ||
tests = listOf( | ||
RunSpecification.Test( | ||
source = RunSpecification.Test.Source.Default("websites"), |
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.
We should fetch it from the DB, or hardcode the websites descriptor ID somewhere.
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.
Now we have OoniTests.Websites.
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.
Is this is empty, it can be removed no?
|
||
val isExpired get() = expirationDate != null && expirationDate < LocalDateTime.now() | ||
|
||
val isDefaultTestDescriptor get() = id.value in 10470..10474 // TODO(aanorbel): switch to OONI reserved namespace |
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.
We could also check if they are in OoniTest
now.
This will be done eventually but converting to draft for now. https://openobservatory.slack.com/archives/GKGRFHXT7/p1733782481912289?thread_ts=1733329764.355889&cid=GKGRFHXT7 |
1323b3b
to
700a097
Compare
700a097
to
196832a
Compare
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.
We should also migrate the ResultModel to stop having descriptorName
and descriptorKey
, and just have descriptorKey
. That will simplify the SQL queries we have that filter by descriptor.
val netTests: List<NetTest>, | ||
val longRunningTests: List<NetTest> = emptyList(), | ||
val source: Source, | ||
val source: InstalledTestDescriptorModel, |
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.
I had mentioned this before, but keeping both the Descriptor
and the InstalledTestDescriptorModel
is just a big duplication of fields now. If we are to keep both because it helps with UpdateStatus
, then we should remove the duplication:
- The
Descriptor
class should just have thesource
andUpdateStatus
- Optionally,
InstalledTestDescriptorModel
could be renamed toDescriptor
andDescriptor
could become aDescriptorItem
orDescriptorWithUpdateStatus
WEBSITES(10470L, "websites"), | ||
INSTANT_MESSAGING(10471L, "instant_messaging"), | ||
CIRCUMVENTION(10472L, "circumvention"), | ||
PERFORMANCE(10473L, "performance"), | ||
EXPERIMENTAL(10474L, "experimental"), |
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.
We're using regular capitalization for enum and sealed classes in this project: WEBSITES -> Websites.
|
||
fun fromId(id: Long) = map[id] | ||
|
||
fun isValidId(id: Long): Boolean = entries.any { it.id == id } |
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.
Since we're already caching the entries as a map, this could be fromId(id) != null
.
import org.ooni.probe.shared.stringMonthArrayResource | ||
import org.ooni.probe.shared.toEpoch | ||
|
||
enum class OoniTest( |
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.
This should be in a separate file, there's no need to be here.
val revision: Long, | ||
) | ||
|
||
val isDefaultTestDescriptor get() = OoniTest.isValidId(id.value.toLongOrNull() ?: -1L) |
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.
Not sure if we should keep with the default concept or not. It's confusing with the NewsMediaScan descriptors, which are default, but not OONI tests. Maybe split this between isOoniDescriptor
and isUninstallable
.
RunSpecification.Full( | ||
tests = listOf( | ||
RunSpecification.Test( | ||
source = RunSpecification.Test.Source.Default("websites"), |
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.
Now we have OoniTests.Websites.
import kotlin.coroutines.CoroutineContext | ||
|
||
class GetBootstrapTestDescriptors( | ||
private val readAssetFile: (String) -> String, |
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.
Not from the PR, but this is not needed.
val descriptor = state.value.descriptor ?: return@onEach | ||
if (descriptor.source !is Descriptor.Source.Installed) return@onEach | ||
setAutoUpdate(descriptor.source.value.id, it.value) | ||
if (descriptor.source == null) return@onEach |
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.
Source can never be null.
else -> ToggleableState.Indeterminate | ||
} | ||
val isRefreshEnabled get() = descriptor?.source is Descriptor.Source.Installed | ||
val isRefreshEnabled get() = descriptor?.source != null |
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.
Now it's always enabled as soon as descriptor != null
no?
runTest { | ||
val descriptor = DescriptorFactory.buildDescriptorWithInstalled() | ||
val installedDescriptor = (descriptor.source as Descriptor.Source.Installed).value | ||
val installedDescriptor = descriptor.source!! |
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.
!!
not needed.
Closes #173, #174
Known issues